CommunicationManagerImpl.h

00001 /**
00002  * @class   CommunicationManagerImpl
00003  * @brief   
00004  *
00005  *
00006  *
00007  *
00008  *
00009  ****************************************************************************
00010  * @version $Id: CommunicationManagerImpl.h 3775 2011-01-01 16:38:17Z alex $
00011  * @author  Alessandro Polo
00012  ****************************************************************************/
00013 /* Copyright (c) 2007-2011, WOSH - Wide Open Smart Home 
00014  * by Alessandro Polo - OpenSmartHome.com
00015  * All rights reserved.
00016  *
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted provided that the following conditions are met:
00019  *     * Redistributions of source code must retain the above copyright
00020  *       notice, this list of conditions and the following disclaimer.
00021  *     * Redistributions in binary form must reproduce the above copyright
00022  *       notice, this list of conditions and the following disclaimer in the
00023  *       documentation and/or other materials provided with the distribution.
00024  *     * Neither the name of the OpenSmartHome.com WOSH nor the
00025  *       names of its contributors may be used to endorse or promote products
00026  *       derived from this software without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
00029  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00030  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00031  * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
00032  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00033  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00034  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00035  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00036  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  ****************************************************************************/
00039 
00040 #ifndef __WOSH_Bundles_CommunicationManager_Impl_H__
00041  #define __WOSH_Bundles_CommunicationManager_Impl_H__
00042 
00043  #include <core/BundleGenericWorker.h>
00044  #include <core/Containers.h>
00045  #include <core/User.h>
00046  #include <core/MessageQueue.h>
00047  #include <core/Notification.h>
00048  #include <framework/communication/NotificationFlow.h>
00049  #include <framework/communication/NotificationConversion.h>
00050  #include <interfaces/communication/Communicator.h>
00051  #include <interfaces/communication/InterpreterService.h>
00052  #include "ICommunicationManagerListener.h"
00053 
00054 
00055 using namespace wosh;
00056 using namespace wosh::communication;
00057 
00058 typedef wosh::XX_MapT<long, NotificationFlow*> tLongNotificationFlowMap
00059 
00060 class CommunicationManagerImpl : public BundleGenericWorker
00061  {
00062     public:
00063         /**
00064          * @brief   Default constructor. Init vars.
00065          * @param bundle [in] the parent bundle, see BundleGenericWorker interface
00066          */
00067         CommunicationManagerImpl( BundleGeneric& bundle );
00068 
00069         /**
00070          * @brief   Deconstructor. If thread is still running, it will be stopped.
00071          */
00072         virtual ~CommunicationManagerImpl();
00073 
00074 
00075     public:
00076 
00077         void evalMessage( const Message& message );
00078 
00079         NotificationFlow* evalNotification_( const Notification* notification, const Message* message );
00080 
00081         bool sendNotification_( NotificationFlow* notification );
00082 
00083         void archiveNotification_( NotificationFlow* notification );
00084 
00085     protected:
00086 
00087         void communicator_reply_sent( WRESULT ret, long notification_id, const URI& source );
00088         void communicator_reply_read( WRESULT ret, long notification_id, const URI& source );
00089 
00090 
00091     protected: // in CommunicationManagerSelector.cpp
00092 
00093         WRESULT intersectCommunicators_( UserInfoCommmunicators* usrComms, const Notification* notification, const std::string& location );
00094 
00095         Interpreter* selectInterpreter_( const Notification* notification, const Communicator* comm );
00096 
00097         UserInfoCommmunicators* getCommunicatorsOf( const std::string& username );
00098 
00099         bool isInterpreterRequired_( const Notification* notification, const Communicator* comm );
00100 
00101 
00102 /** @name Setters
00103  * @{
00104  ******************************************************************************/
00105     public:
00106 
00107         void setListener( ICommunicationManagerListener* list ) { this->listener = list; }
00108 
00109         void setFlowTimeOut( long seconds )                     { this->flowTimeout = seconds; }
00110         void setFlowRetryTime( long seconds )                   { this->flowRetryTime = seconds; }
00111         void setFlowRetryCount( long times )                    { this->flowRetryCount = times; }
00112 
00113 //@}
00114 /** @name Getters
00115  * @{
00116  ******************************************************************************/
00117     public:
00118         long getFlowTimeOut() const                             { return this->flowTimeout; }
00119         long getFlowRetryTime() const                           { return this->flowRetryTime; }
00120         long getFlowRetryCount() const                          { return this->flowRetryCount; }
00121 
00122         tStrCommunicatorMap& getCommunicators()                 { return this->comms; }
00123         tStrInterpreterMap& getInterpreters()                   { return this->transl; }
00124 
00125         tLongNotificationFlowMap& getMessages()             { return this->messages; }
00126         tLongNotificationFlowMap& getMessagesArchived()     { return this->messagesArchived; }
00127 
00128 //@}
00129 /** @name Internal methods
00130  * @{
00131  ******************************************************************************/
00132     protected:
00133 
00134         bool processNotification_( NotificationFlow* notification );
00135 
00136         /**
00137          * @brief   
00138          * @see     running
00139          * @see     
00140          */
00141         virtual void runThread();
00142 
00143 //@}
00144     protected:
00145 
00146         tStrCommunicatorMap comms;          ///< communicators
00147         tStrInterpreterMap transl;          ///< interpreters
00148 
00149         tLongNotificationFlowMap messages;          ///< processing messages cache [flowid, notf*]
00150         tLongNotificationFlowMap messagesArchived;  ///< archived messages cache [flowid, notf*]
00151         long messageArchiveSize;                        ///< size of archived messages cache
00152 
00153         long flowTimeout;                               ///< timeout of notification-flow processing
00154         long flowRetryTime;                             ///< minimum number of seconds between each flow-processing retry [0=disabled]
00155         long flowRetryCount;                            ///< maximum number of retries of flow-processing [0=disabled]
00156 
00157         MessageQueue msgQueue;                          ///< messages' queue
00158 
00159         ICommunicationManagerListener* listener;        ///< callbacks
00160 
00161 
00162 }; // class def
00163 
00164 
00165 #endif //__WOSH_Bundles_CommunicationManager_Impl_H__

Generated on Tue Feb 8 2011 09:32:48 for WOSH system 0.8.888 [wolf] by Alessandro Polo, using DoxyGen 1.7.2 hosted by WOSH Framework