EMIPLIB

mipcomponentchain.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of EMIPLIB, the EDM Media over IP Library.
00004   
00005   Copyright (C) 2006-2011  Hasselt University - Expertise Centre for
00006                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00021   USA
00022 
00023 */
00024 
00029 #ifndef MIPCOMPONENTCHAIN_H
00030 
00031 #define MIPCOMPONENTCHAIN_H
00032 
00033 #include "mipconfig.h"
00034 #include "miperrorbase.h"
00035 #include "mipmessage.h"
00036 #include <jthread/jthread.h>
00037 #include <string>
00038 #include <list>
00039 
00040 class MIPComponent;
00041 
00047 class EMIPLIB_IMPORTEXPORT MIPComponentChain : private jthread::JThread, public MIPErrorBase
00048 {
00049 public:
00052         MIPComponentChain(const std::string &chainName);
00053         virtual ~MIPComponentChain();
00054 
00062         bool start();
00063 
00067         bool stop();
00068 
00072         bool clearChain();
00073 
00078         bool setChainStart(MIPComponent *pStartComponent);
00079 
00100         bool addConnection(MIPComponent *pPullComponent, MIPComponent *pPushCompontent, bool feedback = false,
00101                           uint32_t allowedMessageTypes = MIPMESSAGE_TYPE_ALL, 
00102                           uint32_t allowedSubmessageTypes = MIPMESSAGE_TYPE_ALL);
00103 
00105         bool deleteConnection(MIPComponent *pPullComponent, MIPComponent *pPushCompontent, bool feedback = false,
00106                           uint32_t allowedMessageTypes = MIPMESSAGE_TYPE_ALL, 
00107                           uint32_t allowedSubmessageTypes = MIPMESSAGE_TYPE_ALL);
00108 
00112         std::string getName() const                                                                     { return m_chainName; }
00113         
00115         bool rebuild();
00116 protected:
00125         virtual void onThreadExit(bool error, const std::string &errorComponent,
00126                                   const std::string &errorDescription)                                  { }
00127 private:
00128         class MIPConnection
00129         {
00130         public:
00131                 MIPConnection(MIPComponent *pPull, MIPComponent *pPush, bool feedback, uint32_t mask1,
00132                               uint32_t mask2)                                                           { m_mask1 = mask1; m_mask2 = mask2; m_pPull = pPull; m_pPush = pPush; m_marked = false; m_feedback = feedback; }
00133                 MIPComponent *getPullComponent() const                                                  { return m_pPull; }
00134                 MIPComponent *getPushComponent() const                                                  { return m_pPush; }
00135                 bool isMarked() const                                                                   { return m_marked; }
00136                 void setMark(bool v)                                                                    { m_marked = v; }
00137                 uint32_t getMask1() const                                                               { return m_mask1; }
00138                 uint32_t getMask2() const                                                               { return m_mask2; }
00139                 bool giveFeedback() const                                                               { return m_feedback; }
00140                 bool operator==(const MIPConnection &c) const                                           { if (m_pPull == c.m_pPull && m_pPush == c.m_pPush && m_mask1 == c.m_mask1 && m_mask2 == c.m_mask2 && m_feedback == c.m_feedback) return true; return false; }
00141         private:
00142                 MIPComponent *m_pPull, *m_pPush;
00143                 uint32_t m_mask1;
00144                 uint32_t m_mask2;
00145                 bool m_marked;
00146                 bool m_feedback;
00147         };
00148 
00149         void *Thread();
00150         bool orderConnections(std::list<MIPConnection> &orderedConnections);
00151         bool buildFeedbackList(std::list<MIPConnection> &orderedList, std::list<MIPComponent *> &feedbackChain);
00152         void copyConnectionInfo(const std::list<MIPConnection> &orderedList, const std::list<MIPComponent *> &feedbackChain);
00153         
00154         std::string m_chainName;
00155         std::list<MIPConnection> m_inputConnections;
00156         std::list<MIPConnection> m_orderedConnections;
00157         std::list<MIPComponent *> m_feedbackChain;
00158         MIPComponent *m_pInputChainStart;       
00159         MIPComponent *m_pInternalChainStart;
00160 
00161         jthread::JMutex m_loopMutex;
00162         jthread::JMutex m_chainMutex;
00163         bool m_stopLoop;
00164 };
00165 
00166 #endif // MIPCOMPONENTCHAIN_H
00167