our current experimental Neutrino branch

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@27 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
mrcolor
2009-12-08 11:05:11 +00:00
commit bc5bd4154e
876 changed files with 193775 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
noinst_LIBRARIES = libtuxbox-eventserver.a
AM_CPPFLAGS = -fno-rtti -fno-exceptions
libtuxbox_eventserver_a_SOURCES = eventserver.cpp

View File

@@ -0,0 +1,115 @@
/*
$Header: /cvs/tuxbox/apps/misc/libs/libeventserver/eventserver.cpp,v 1.12 2003/03/14 06:25:49 obi Exp $
Event-Server - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include "eventserver.h"
void CEventServer::registerEvent2(const unsigned int eventID, const unsigned int ClientID, const std::string udsName)
{
strcpy(eventData[eventID][ClientID].udsName, udsName.c_str());
}
void CEventServer::registerEvent(const int fd)
{
commandRegisterEvent msg;
int readresult= read(fd, &msg, sizeof(msg));
if ( readresult<= 0 )
perror("[eventserver]: read");
// printf("[eventserver]: read from %d %x bytes %d/%d\n", fd, errno, readresult, sizeof(msg));
// printf("[eventserver]: registered event (%d) to: %d - %s\n", msg.eventID, msg.clientID, msg.udsName);
registerEvent2(msg.eventID, msg.clientID, msg.udsName);
}
void CEventServer::unRegisterEvent2(const unsigned int eventID, const unsigned int ClientID)
{
eventData[eventID].erase( ClientID );
}
void CEventServer::unRegisterEvent(const int fd)
{
commandUnRegisterEvent msg;
read(fd, &msg, sizeof(msg));
unRegisterEvent2(msg.eventID, msg.clientID);
}
void CEventServer::sendEvent(const unsigned int eventID, const initiators initiatorID, const void* eventbody, const unsigned int eventbodysize)
{
eventClientMap notifyClients = eventData[eventID];
for(eventClientMap::iterator pos = notifyClients.begin(); pos != notifyClients.end(); pos++)
{
//allen clients ein event schicken
eventClient client = pos->second;
sendEvent2Client(eventID, initiatorID, &client, eventbody, eventbodysize);
}
}
bool CEventServer::sendEvent2Client(const unsigned int eventID, const initiators initiatorID, const eventClient* ClientData, const void* eventbody, const unsigned int eventbodysize)
{
struct sockaddr_un servaddr;
int clilen, sock_fd;
memset(&servaddr, 0, sizeof(struct sockaddr_un));
servaddr.sun_family = AF_UNIX;
strcpy(servaddr.sun_path, ClientData->udsName);
clilen = sizeof(servaddr.sun_family) + strlen(servaddr.sun_path);
if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
perror("[eventserver]: socket");
return false;
}
if(connect(sock_fd, (struct sockaddr*) &servaddr, clilen) <0 )
{
char errmsg[128];
snprintf(errmsg, 128, "[eventserver]: connect (%s)", ClientData->udsName);
perror(errmsg);
close(sock_fd);
return false;
}
eventHead head;
head.eventID = eventID;
head.initiatorID = initiatorID;
head.dataSize = eventbodysize;
int written = write(sock_fd, &head, sizeof(head));
// printf ("[eventserver]: sent 0x%x - following eventbody= %d\n", written, eventbodysize );
if(eventbodysize!=0)
{
written = write(sock_fd, eventbody, eventbodysize);
// printf ("[eventserver]: eventbody sent 0x%x - peventbody= %x eventbody= %x\n", written, (unsigned)eventbody, *(unsigned*)eventbody );
}
close(sock_fd);
return true;
}

View File

@@ -0,0 +1,95 @@
/*
$Header: /cvs/tuxbox/apps/misc/libs/libeventserver/eventserver.h,v 1.14 2004/05/06 15:06:30 thegoodguy Exp $
Event-Server - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __libevent__
#define __libevent__
#include <string>
#include <map>
class CEventServer
{
public:
enum initiators
{
INITID_CONTROLD,
INITID_SECTIONSD,
INITID_ZAPIT,
INITID_TIMERD,
INITID_HTTPD,
INITID_NEUTRINO,
INITID_GENERIC_INPUT_EVENT_PROVIDER
};
struct commandRegisterEvent
{
unsigned int eventID;
unsigned int clientID;
char udsName[50];
};
struct commandUnRegisterEvent
{
unsigned int eventID;
unsigned int clientID;
};
struct eventHead
{
unsigned int eventID;
unsigned int initiatorID;
unsigned int dataSize;
};
void registerEvent2(const unsigned int eventID, const unsigned int ClientID, const std::string udsName);
void registerEvent(const int fd);
void unRegisterEvent2(const unsigned int eventID, const unsigned int ClientID);
void unRegisterEvent(const int fd);
void sendEvent(const unsigned int eventID, const initiators initiatorID, const void* eventbody = NULL, const unsigned int eventbodysize = 0);
protected:
struct eventClient
{
char udsName[50];
};
//key: ClientID // Map is a Sorted Associative Container
typedef std::map<unsigned int, eventClient> eventClientMap; // -> clients with lower ClientID receive events first
//key: eventID
std::map<unsigned int, eventClientMap> eventData;
bool sendEvent2Client(const unsigned int eventID, const initiators initiatorID, const eventClient* ClientData, const void* eventbody = NULL, const unsigned int eventbodysize = 0);
};
#endif