From cd23bf5e1d2e1d134df91f23ebfd761d770a99db Mon Sep 17 00:00:00 2001 From: christian mueller Date: Fri, 23 Dec 2011 11:49:44 +0100 Subject: * fixed no compile bug * fixed sockethandler loop --- AudioManagerDaemon/src/DBusWrapper.cpp | 4 +- AudioManagerDaemon/src/SocketHandler.cpp | 84 ++++++++++++++++---------------- AudioManagerDaemon/test/CMakeLists.txt | 2 +- includes/SocketHandler.h | 3 +- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/AudioManagerDaemon/src/DBusWrapper.cpp b/AudioManagerDaemon/src/DBusWrapper.cpp index b631a5f..a34b6e8 100644 --- a/AudioManagerDaemon/src/DBusWrapper.cpp +++ b/AudioManagerDaemon/src/DBusWrapper.cpp @@ -387,9 +387,9 @@ void DBusWrapper::toggleTimeout(DBusTimeout *timeout, void* userData) bool am::DBusWrapper::dbusDispatchCallback(const sh_pollHandle_t handle, void *userData) { - bool returnVal=false; + bool returnVal=true; dbus_connection_ref(mDbusConnection); - if (dbus_connection_dispatch(mDbusConnection)==DBUS_DISPATCH_COMPLETE) returnVal=true; + if (dbus_connection_dispatch(mDbusConnection)==DBUS_DISPATCH_COMPLETE) returnVal=false; dbus_connection_unref(mDbusConnection); DLT_LOG(DLT_CONTEXT,DLT_LOG_INFO, DLT_STRING("DBusWrapper::dbusDispatchCallback was called")); return returnVal; diff --git a/AudioManagerDaemon/src/SocketHandler.cpp b/AudioManagerDaemon/src/SocketHandler.cpp index fa04f3a..1785b46 100644 --- a/AudioManagerDaemon/src/SocketHandler.cpp +++ b/AudioManagerDaemon/src/SocketHandler.cpp @@ -79,6 +79,7 @@ void SocketHandler::start_listenting() if(mRecreatePollfds) { + mfdPollingArray.clear(); //there was a change in the setup, so we need to recreate the fdarray from the list std::for_each(mListPoll.begin(),mListPoll.end(),CopyPollfd(mfdPollingArray)); mRecreatePollfds=false; @@ -94,60 +95,59 @@ void SocketHandler::start_listenting() { //todo: here could be a timer that makes sure naughty plugins return! - //first, we check what happened: - mPollfd_t::iterator iterator=mfdPollingArray.begin(); - mPollfd_t::iterator iteratorEnd=mfdPollingArray.end(); - for(;iterator!=iteratorEnd;++iterator) + //get all indexes of the fired events and save them int hitList + hitList.clear(); + std::vector::iterator it=mfdPollingArray.begin(); + do { - //get all indexes of the fired events and save them int hitList - hitList.clear(); - std::vector::iterator it=mfdPollingArray.begin(); - do - { - it=std::find_if(it,mfdPollingArray.end(),onlyFiredEvents); - if (it!=mfdPollingArray.end()) hitList.push_back(std::distance(mfdPollingArray.begin(), it++)); + it=std::find_if(it,mfdPollingArray.end(),onlyFiredEvents); + if (it!=mfdPollingArray.end()) hitList.push_back(std::distance(mfdPollingArray.begin(), it++)); - } while (it!=mfdPollingArray.end()); + } while (it!=mfdPollingArray.end()); - //stage 1, call firedCB for all matched events, but only if callback is not zero! - std::list::iterator hListIt=hitList.begin(); - for(;hListIt!=hitList.end();++hListIt) + //stage 1, call firedCB for all matched events, but only if callback is not zero! + std::list::iterator hListIt=hitList.begin(); + for(;hListIt!=hitList.end();++hListIt) + { + shPollFired* fire=NULL; + if ((fire=mListPoll.at(*hListIt).firedCB)!=NULL) fire->Call(mfdPollingArray.at(*hListIt),mListPoll.at(*hListIt).handle,mListPoll.at(*hListIt).userData); + } + + //stage 2, lets ask around if some dispatching is necessary, if not, they are taken from the hitlist + hListIt=hitList.begin(); + for(;hListIt!=hitList.end();++hListIt) + { + shPollCheck* check=NULL; + if ((check=mListPoll.at(*hListIt).checkCB)!=NULL) { - shPollFired* fire=NULL; - if ((fire=mListPoll.at(*hListIt).firedCB)!=NULL) fire->Call(mfdPollingArray.at(*hListIt),mListPoll.at(*hListIt).handle,mListPoll.at(*hListIt).userData); + if (!check->Call(mListPoll.at(*hListIt).handle,mListPoll.at(*hListIt).userData)) + { + hListIt=hitList.erase(hListIt); + } } + } - //stage 2, lets ask around if some dispatching is necessary, if not, they are taken from the hitlist + //stage 3, the ones left need to dispatch, we do this as long as there is something to dispatch.. + do + { hListIt=hitList.begin(); for(;hListIt!=hitList.end();++hListIt) { - shPollCheck* check=NULL; - if ((check=mListPoll.at(*hListIt).checkCB)!=NULL) + shPollDispatch *dispatch=NULL; + if((dispatch=mListPoll.at(*hListIt).dispatchCB)!=NULL) { - if (!check->Call(mListPoll.at(*hListIt).handle,mListPoll.at(*hListIt).userData)) + if (!dispatch->Call(mListPoll.at(*hListIt).handle,mListPoll.at(*hListIt).userData)) { hListIt=hitList.erase(hListIt); } } - } - - //stage 3, the ones left need to dispatch, we do this as long as there is something to dispatch.. - do - { - hListIt=hitList.begin(); - for(;hListIt!=hitList.end();++hListIt) + else //there is no dispatch function, so we just remove the file from the list... { - shPollDispatch *dispatch=NULL; - if((dispatch=mListPoll.at(*hListIt).dispatchCB)!=NULL) - { - if (dispatch->Call(mListPoll.at(*hListIt).handle,mListPoll.at(*hListIt).userData)) - { - hListIt=hitList.erase(hListIt); - } - } + hListIt=hitList.erase(hListIt); } - } while (!hitList.empty()); - } + } + } while (!hitList.empty()); + } else //Timerevent { @@ -177,8 +177,8 @@ am_Error_e SocketHandler::addFDPoll(const int fd,const int16_t event, shPollPrep if (!fdIsValid(fd)) return E_NON_EXISTENT; sh_poll_s pollData; - pollData.handle=++mLastInsertedPollHandle; pollData.pollfdValue.fd=fd; + pollData.handle=++mLastInsertedPollHandle; pollData.pollfdValue.events=event; pollData.pollfdValue.revents=0; pollData.userData=userData; @@ -227,7 +227,7 @@ am_Error_e SocketHandler::removeFDPoll(const sh_pollHandle_t handle) * @param handle the handle that is created for the timer is returned. Can be used to remove the timer * @return E_OK in case of success */ -am_Error_e SocketHandler::addTimer(const timespec timeouts,TBasicTimerCallback*& callback,sh_timerHandle_t& handle, void * userData) +am_Error_e SocketHandler::addTimer(const timespec timeouts,shTimerCallBack*& callback,sh_timerHandle_t& handle, void * userData) { assert(!((timeouts.tv_sec==0) && (timeouts.tv_nsec==0))); assert(callback!=NULL); @@ -433,7 +433,9 @@ void SocketHandler::SubstractTime::operator ()(timer_s & t) const void SocketHandler::CopyPollfd::operator ()(const sh_poll_s & row) { - mArray.push_back(row.pollfdValue); + pollfd temp=row.pollfdValue; + temp.revents=0; + mArray.push_back(temp); } /* namespace am */ diff --git a/AudioManagerDaemon/test/CMakeLists.txt b/AudioManagerDaemon/test/CMakeLists.txt index 7f8c054..f00ec41 100644 --- a/AudioManagerDaemon/test/CMakeLists.txt +++ b/AudioManagerDaemon/test/CMakeLists.txt @@ -18,4 +18,4 @@ FIND_PACKAGE(GTest REQUIRED) add_subdirectory (database) add_subdirectory (routingInterface) add_subdirectory (controlInterface) -#add_subdirectory (sockethandler) +add_subdirectory (sockethandler) diff --git a/includes/SocketHandler.h b/includes/SocketHandler.h index ab2bf33..74f20ac 100644 --- a/includes/SocketHandler.h +++ b/includes/SocketHandler.h @@ -59,7 +59,6 @@ public: am_Error_e stopTimer(const sh_timerHandle_t handle); void start_listenting(); void stop_listening(); - private: struct timer_s //!