From f2f42846720bcb6278e30d9234e911152507de8b Mon Sep 17 00:00:00 2001 From: christian mueller Date: Fri, 23 Mar 2012 13:43:37 +0100 Subject: * [GAM-46] improvements on CAmSockthandler. * Needed adoptions on CAmSockethandler tests * Small bug in CAmSerializer Signed-off-by: christian mueller --- include/shared/CAmSerializer.h | 2 +- include/shared/CAmSocketHandler.h | 293 ++++++++++++++++++++++++++++---------- 2 files changed, 219 insertions(+), 76 deletions(-) (limited to 'include') diff --git a/include/shared/CAmSerializer.h b/include/shared/CAmSerializer.h index a88c0ad..a8c63b1 100644 --- a/include/shared/CAmSerializer.h +++ b/include/shared/CAmSerializer.h @@ -976,7 +976,7 @@ public: short event = 0; sh_pollHandle_t handle; event |= POLLIN; - iSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, NULL, &dispatcherCallbackT, NULL, handle); + iSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, handle); } ~CAmSerializer() diff --git a/include/shared/CAmSocketHandler.h b/include/shared/CAmSocketHandler.h index 9c3b6e7..83d2352 100644 --- a/include/shared/CAmSocketHandler.h +++ b/include/shared/CAmSocketHandler.h @@ -21,7 +21,6 @@ #include "audiomanagertypes.h" #include -#include #include #include #include @@ -36,11 +35,55 @@ static volatile sig_atomic_t gDispatchDone = 0; //this global is used to stop th typedef uint16_t sh_timerHandle_t; //! rListTimerIter; + class CAmShSubstractTime //!Call(row.pollfdValue, row.handle, row.userData); + } + }; + + class CAmShCallPrep + { + public: + CAmShCallPrep(){}; + void operator()(sh_poll_s& row) + { + if (row.prepareCB) + row.prepareCB->Call(row.handle, row.userData); + } + }; + + class CAmShCallTimer + { + public: + CAmShCallTimer(){}; + void operator()(sh_timer_s& row) + { + row.callback->Call(row.handle, row.userData); + } + }; + + class CAmShCountdownUp + { + public: + CAmShCountdownUp(){}; + bool operator()(sh_timer_s& row) + { + if (row.countdown.tv_nsec == 0 && row.countdown.tv_sec == 0) + return (true); + return (false); + } + }; + + class CAmShCountdownSame + { + private: + sh_timer_s mCompareValue; + public: + CAmShCountdownSame(sh_timer_s& a) : + mCompareValue(a) + {} + bool operator()(const sh_timer_s& b) { + return ((mCompareValue.countdown.tv_sec == b.countdown.tv_sec) && (mCompareValue.countdown.tv_nsec == b.countdown.tv_nsec) ? true : false); } - void operator()(const sh_poll_s& row); }; bool fdIsValid(const int fd) const; void initTimer(); void timerUp(); + void timerCorrection(); int timespec2ms(const timespec& time); timespec* insertTime(timespec& buffertime); + static bool compareCountdown(const sh_timer_s& a, const sh_timer_s& b) { return ((a.countdown.tv_sec == b.countdown.tv_sec) ? (a.countdown.tv_nsec < b.countdown.tv_nsec) : (a.countdown.tv_sec < b.countdown.tv_sec)); } - static bool onlyFiredEvents(const pollfd& a) + /** + * Subtracts b from a + * @param a + * @param b + * @return subtracted value + */ + static timespec timespecSub(const timespec& a, const timespec& b) + { + timespec result; + + if ((a.tv_sec < b.tv_sec) || ((a.tv_sec == b.tv_sec) && (a.tv_nsec <= b.tv_nsec))) + { + result.tv_sec = result.tv_nsec = 0; + } + else + { + result.tv_sec = a.tv_sec - b.tv_sec; + if (a.tv_nsec < b.tv_nsec) + { + result.tv_nsec = a.tv_nsec + 1000000000L - b.tv_nsec; + result.tv_sec--; /* Borrow a second. */ + } + else + { + result.tv_nsec = a.tv_nsec - b.tv_nsec; + } + } + return (result); + } + + static timespec timespecAdd(const timespec& a, const timespec b) + { + timespec result; + result.tv_sec = a.tv_sec + b.tv_sec; + result.tv_nsec = a.tv_nsec + b.tv_nsec; + if (result.tv_nsec >= 1000000000L) + { + result.tv_sec++; + result.tv_nsec = result.tv_nsec - 1000000000L; + } + return (result); + } + + static int timespecCompare(const timespec& a, const timespec& b) + { + //less + if (a.tv_sec < b.tv_sec) + return (-1); + //greater + else if (a.tv_sec > b.tv_sec) + return (1); + //less + else if (a.tv_nsec < b.tv_nsec) + return (-1); + //greater + else if (a.tv_nsec > b.tv_nsec) + return (1); + //equal + else + return (0); + } + + inline static bool eventFired(const pollfd& a) { return (a.revents == 0 ? false : true); } - //todo: maybe we could simplify mListActiveTimer to hold only the handle and the countdown .... + inline static bool noDispatching(const sh_poll_s& a) + { + //remove from list of there is no checkCB + if (!a.checkCB) + return (true); + return (!a.checkCB->Call(a.handle, a.userData)); + } + + inline static bool dispatchingFinished(const sh_poll_s& a) + { + //remove from list of there is no dispatchCB + if (!a.dispatchCB) + return (true); + return (!a.dispatchCB->Call(a.handle, a.userData)); + } + mListPollfd_t mfdPollingArray; mListPoll_t mListPoll; std::list mListTimer; //! mListActiveTimer; //!