diff options
Diffstat (limited to 'AudioManagerDaemon')
-rw-r--r-- | AudioManagerDaemon/src/RoutingSender.cpp | 2 | ||||
-rw-r--r-- | AudioManagerDaemon/src/SocketHandler.cpp | 3 | ||||
-rw-r--r-- | AudioManagerDaemon/src/main.cpp | 1 | ||||
-rw-r--r-- | AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp | 80 | ||||
-rw-r--r-- | AudioManagerDaemon/test/sockethandler/sockethandlerTest.h | 7 |
5 files changed, 80 insertions, 13 deletions
diff --git a/AudioManagerDaemon/src/RoutingSender.cpp b/AudioManagerDaemon/src/RoutingSender.cpp index a6de266..3b5bdad 100644 --- a/AudioManagerDaemon/src/RoutingSender.cpp +++ b/AudioManagerDaemon/src/RoutingSender.cpp @@ -27,6 +27,7 @@ #include <dirent.h> #include <dlfcn.h> #include <dlt/dlt.h> +#include <assert.h> #include "PluginTemplate.h" using namespace am; @@ -123,6 +124,7 @@ RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirecto //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain.... router->returnBusName(routerInterface.busName); + assert(!routerInterface.busName.empty()); mListInterfaces.push_back(routerInterface); mListLibraryHandles.push_back(tempLibHandle); } diff --git a/AudioManagerDaemon/src/SocketHandler.cpp b/AudioManagerDaemon/src/SocketHandler.cpp index 1785b46..10e0f98 100644 --- a/AudioManagerDaemon/src/SocketHandler.cpp +++ b/AudioManagerDaemon/src/SocketHandler.cpp @@ -32,6 +32,8 @@ #include <features.h> //todo: implement ppoll +//todo: signal handling here +//todo: implement time correction if timer was interrupted by call #include <iostream> //todo remove @@ -43,6 +45,7 @@ SocketHandler::SocketHandler() mListActiveTimer(), mNextTimer(), mLastInsertedHandle(0), + mLastInsertedPollHandle(0), mDispatch(true), mRecreatePollfds(true) { diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index 5edc6cb..74a412c 100644 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -110,6 +110,7 @@ int main(int argc, char *argv[]) //the controller should startup the interfaces - this is just for testing iCommandSender.startupInterface(&iCommandReceiver); iRoutingSender.startupRoutingInterface(&iRoutingReceiver); + iRoutingSender.routingInterfacesReady(); #ifdef WITH_SOCKETHANDLER_LOOP iSocketHandler.start_listenting(); diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp index 69af391..87b2751 100644 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp +++ b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.cpp @@ -84,11 +84,54 @@ void am::timerCallBack::timer4Callback(sh_timerHandle_t, void* userData) void* playWithSocketServer(void* data) { SocketHandler myHandler; - SamplePlugin myplugin(&myHandler); + SamplePlugin::sockType_e type=SamplePlugin::INET; + SamplePlugin myplugin(&myHandler,type); myHandler.start_listenting(); } +void* playWithUnixSocketServer(void* data) +{ + SocketHandler myHandler; + SamplePlugin::sockType_e type=SamplePlugin::UNIX; + SamplePlugin myplugin(&myHandler,type); + myHandler.start_listenting(); +} + +TEST(sockethandlerTest,playWithUNIXSockets) +{ + pthread_t serverThread; + char buffer[3000]; + struct sockaddr_un servAddr; + int socket_; + + //creates a thread that handles the serverpart + pthread_create(&serverThread,NULL,playWithUnixSocketServer,NULL); + + sleep(1); //we need that here because the port needs to be opened + if ((socket_ = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + { + std::cout<<"socket problem"<<std::endl; + + } + + memset(&servAddr, 0, sizeof(servAddr)); + strcpy(servAddr.sun_path, SOCK_PATH); + servAddr.sun_family = AF_UNIX; + if (connect(socket_, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) + { + std::cout<<"ERROR: connect() failed\n"<<std::endl; + } + + for (int i=0;i<=1000;i++) + { + std::string string("Got It?"); + send(socket_,string.c_str(),string.size(),0); + } + std::string string("finish!"); + send(socket_,string.c_str(),string.size(),0); + pthread_join(serverThread,NULL); +} TEST(sockethandlerTest,playWithSockets) { @@ -176,7 +219,7 @@ int main(int argc, char **argv) return RUN_ALL_TESTS(); } -am::SamplePlugin::SamplePlugin(SocketHandler *mySocketHandler) +am::SamplePlugin::SamplePlugin(SocketHandler *mySocketHandler, sockType_e socketType) :connectFiredCB(this,&SamplePlugin::connectSocket), receiveFiredCB(this,&SamplePlugin::receiveData), sampleDispatchCB(this,&SamplePlugin::dispatchData), @@ -189,19 +232,32 @@ am::SamplePlugin::SamplePlugin(SocketHandler *mySocketHandler) int ret; int yes = 1; + int socketHandle; struct sockaddr_in servAddr; + struct sockaddr_un unixAddr; unsigned int servPort = 6060; - int socketHandle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - setsockopt(socketHandle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); - memset(&servAddr, 0, sizeof(servAddr)); - servAddr.sin_family = AF_INET; - servAddr.sin_addr.s_addr = INADDR_ANY; - servAddr.sin_port = htons(servPort); - if (bind(socketHandle, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) - { - std::cout<<"bind ok"<<std::endl; - } /* if */ + switch (socketType) + { + case UNIX: + socketHandle = socket(AF_UNIX, SOCK_STREAM, 0); + unixAddr.sun_family = AF_UNIX; + strcpy(unixAddr.sun_path,SOCK_PATH); + unlink(unixAddr.sun_path); + bind(socketHandle, (struct sockaddr *)&unixAddr, strlen(unixAddr.sun_path) + sizeof(unixAddr.sun_family)); + break; + case INET: + socketHandle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + setsockopt(socketHandle, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + memset(&servAddr, 0, sizeof(servAddr)); + servAddr.sin_family = AF_INET; + servAddr.sin_addr.s_addr = INADDR_ANY; + servAddr.sin_port = htons(servPort); + bind(socketHandle, (struct sockaddr *) &servAddr, sizeof(servAddr)); + break; + default: + break; + } if (listen(socketHandle, 3) < 0) { diff --git a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h index d58c46f..18eff7e 100644 --- a/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h +++ b/AudioManagerDaemon/test/sockethandler/sockethandlerTest.h @@ -17,7 +17,12 @@ namespace am { class SamplePlugin { public: - SamplePlugin(SocketHandler *mySocketHandler); + enum sockType_e + { + UNIX, + INET + }; + SamplePlugin(SocketHandler *mySocketHandler,sockType_e socketType); virtual ~SamplePlugin() {}; void connectSocket(const pollfd pollfd,const sh_pollHandle_t handle, void* userData); void receiveData(const pollfd pollfd,const sh_pollHandle_t handle, void* userData); |