/** * Copyright (C) 2011, BMW AG * * GeniviAudioMananger DbusPlugin * * \file RoutingSender.h * * \date 20-Oct-2011 3:42:04 PM * \author Christian Mueller (christian.ei.mueller@bmw.de) * * \section License * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause) * Copyright (C) 2011, BMW AG Christian Mueller Christian.ei.mueller@bmw.de * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. * 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 Lesser General Public License, version 2.1, for more details. * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see . * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense. * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception. * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned. * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception. * * THIS CODE HAS BEEN GENERATED BY ENTERPRISE ARCHITECT GENIVI MODEL. PLEASE CHANGE ONLY IN ENTERPRISE ARCHITECT AND GENERATE AGAIN */ #ifndef ROUTINGSENDER_H_ #define ROUTINGSENDER_H_ #include #include "RoutingReceiverAsyncShadow.h" #include namespace am { class WorkerThreadPool; /** * Base class for workers implements everything that is needed to implement a workerthread * inherit from this class when adding new workers */ class Worker { public: Worker(WorkerThreadPool* pool); virtual ~Worker(){}; /** * needs to be overwritten, this function is called when the worker should start to work */ void virtual start2work()=0; /** * needs to be overwritten, this function is called when the worker thread is canceled. Should be used for * clean up and sending important messages */ void virtual cancelWork()=0; /** * waits for a semaphore with a timeout. This leaves the Threadpool the chance to interrupt the processing * You should call whenever waiting on some event, even with time=0 in order to make sure that cancel events are * received * @param time time until timeout in timespec format * @return true if thread is canceled. Then just return start2work function so that the thread is given back to the pool */ bool timedWait(timespec time); /** * the semaphore for cancellation is set by the thread automatically... * @param cancel */ void setCancelSempaphore(sem_t* cancel); WorkerThreadPool* pPool; private: sem_t* mCancelSem; // mListWorkers; // createDomainTable(); std::vector createSinkTable(); std::vector createSourceTable(); std::vector createGatewayTable(); RoutingReceiverAsyncShadow mShadow; RoutingReceiveInterface* mReceiveInterface; SocketHandler *mSocketHandler; std::vector mDomains; std::vector mSinks; std::vector mSources; std::vector mGateways; std::map mMapHandleWorker; std::map mMapConnectionIDRoute; WorkerThreadPool mPool; pthread_t mInterruptThread; static pthread_mutex_t mMapConnectionMutex; static pthread_mutex_t mMapHandleWorkerMutex; static pthread_mutex_t mSinksMutex; static pthread_mutex_t mSourcesMutex; static pthread_mutex_t mDomainsMutex; }; /** * worker to for connection */ class asycConnectWorker : public Worker { public: asycConnectWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_Handle_s mHandle; am_connectionID_t mConnectionID; am_sourceID_t mSourceID; am_sinkID_t mSinkID; am_ConnectionFormat_e mConnectionFormat; }; /** * worker for disconnecting */ class asycDisConnectWorker : public Worker { public: asycDisConnectWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_connectionID_t connectionID); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_Handle_s mHandle; am_connectionID_t mConnectionID; am_ConnectionFormat_e mConnectionFormat; }; /** * worker to for connection */ #include #include #include class asyncSetSinkVolumeWorker : public Worker { public: asyncSetSinkVolumeWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_volume_t currentVolume,const am_Handle_s handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_volume_t mCurrentVolume; am_Handle_s mHandle; am_sinkID_t mSinkID; am_volume_t mVolume; am_RampType_e mRamp; am_time_t mTime; }; class asyncSetSourceVolumeWorker : public Worker { public: asyncSetSourceVolumeWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_volume_t currentVolume,const am_Handle_s handle, const am_sourceID_t SourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_volume_t mCurrentVolume; am_Handle_s mHandle; am_sourceID_t mSourceID; am_volume_t mVolume; am_RampType_e mRamp; am_time_t mTime; }; class asyncSetSourceStateWorker : public Worker { public: asyncSetSourceStateWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_sourceID_t sourceID, const am_SourceState_e state); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_Handle_s mHandle; am_sourceID_t mSourceID; am_SourceState_e mSourcestate; }; class asyncSetSinkSoundPropertyWorker : public Worker { public: asyncSetSinkSoundPropertyWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sinkID_t sinkID); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_Handle_s mHandle; am_sinkID_t mSinkID; am_SoundProperty_s mSoundProperty; }; class asyncSetSourceSoundPropertyWorker : public Worker { public: asyncSetSourceSoundPropertyWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_Handle_s handle, const am_SoundProperty_s soundProperty, const am_sourceID_t sourceID); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_Handle_s mHandle; am_sourceID_t mSourceID; am_SoundProperty_s mSoundProperty; }; class asyncDomainStateChangeWorker : public Worker { public: asyncDomainStateChangeWorker(AsyncRoutingSender * asyncSender,WorkerThreadPool* pool, RoutingReceiverAsyncShadow* shadow, const am_domainID_t domainID, const am_DomainState_e domainState); void start2work(); void cancelWork(); private: AsyncRoutingSender * mAsyncSender; RoutingReceiverAsyncShadow *mShadow; am_domainID_t mDomainID; am_DomainState_e mDomainState; }; } #endif /* ROUTINGSENDER_H_ */