Ginga  0.13.6
 All Classes Namespaces Functions Variables
CompositeExecutionObject.h
1 /******************************************************************************
2 Este arquivo eh parte da implementacao do ambiente declarativo do middleware
3 Ginga (Ginga-NCL).
4 
5 Direitos Autorais Reservados (c) 1989-2007 PUC-Rio/Laboratorio TeleMidia
6 
7 Este programa eh software livre; voce pode redistribui-lo e/ou modificah-lo sob
8 os termos da Licenca Publica Geral GNU versao 2 conforme publicada pela Free
9 Software Foundation.
10 
11 Este programa eh distribuido na expectativa de que seja util, porem, SEM
12 NENHUMA GARANTIA; nem mesmo a garantia implicita de COMERCIABILIDADE OU
13 ADEQUACAO A UMA FINALIDADE ESPECIFICA. Consulte a Licenca Publica Geral do
14 GNU versao 2 para mais detalhes.
15 
16 Voce deve ter recebido uma copia da Licenca Publica Geral do GNU versao 2 junto
17 com este programa; se nao, escreva para a Free Software Foundation, Inc., no
18 endereco 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
19 
20 Para maiores informacoes:
21 ncl @ telemidia.puc-rio.br
22 http://www.ncl.org.br
23 http://www.ginga.org.br
24 http://www.telemidia.puc-rio.br
25 ******************************************************************************
26 This file is part of the declarative environment of middleware Ginga (Ginga-NCL)
27 
28 Copyright: 1989-2007 PUC-RIO/LABORATORIO TELEMIDIA, All Rights Reserved.
29 
30 This program is free software; you can redistribute it and/or modify it under
31 the terms of the GNU General Public License version 2 as published by
32 the Free Software Foundation.
33 
34 This program is distributed in the hope that it will be useful, but WITHOUT ANY
35 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36 PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
37 details.
38 
39 You should have received a copy of the GNU General Public License version 2
40 along with this program; if not, write to the Free Software
41 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 
43 For further information contact:
44 ncl @ telemidia.puc-rio.br
45 http://www.ncl.org.br
46 http://www.ginga.org.br
47 http://www.telemidia.puc-rio.br
48 *******************************************************************************/
49 
50 #ifndef _COMPOSITEEXECUTIONOBJECT_H_
51 #define _COMPOSITEEXECUTIONOBJECT_H_
52 
53 extern "C" {
54 #include <assert.h>
55 }
56 
57 #include "ncl/components/Node.h"
58 #include "ncl/components/ContextNode.h"
59 using namespace ::br::pucrio::telemidia::ncl::components;
60 
61 #include "ncl/connectors/EventUtil.h"
62 using namespace ::br::pucrio::telemidia::ncl::connectors;
63 
64 #include "ncl/link/Link.h"
65 using namespace ::br::pucrio::telemidia::ncl::link;
66 
67 #include "IEventListener.h"
68 #include "FormatterEvent.h"
69 #include "PresentationEvent.h"
70 using namespace ::br::pucrio::telemidia::ginga::ncl::model::event;
71 
72 #include "FormatterCausalLink.h"
73 #include "FormatterLink.h"
74 #include "LinkListener.h"
75 using namespace ::br::pucrio::telemidia::ginga::ncl::model::link;
76 
77 #include "NodeNesting.h"
78 #include "CascadingDescriptor.h"
79 #include "ExecutionObject.h"
80 
81 #include <vector>
82 #include <map>
83 #include <string>
84 using namespace std;
85 
86 namespace br {
87 namespace pucrio {
88 namespace telemidia {
89 namespace ginga {
90 namespace ncl {
91 namespace model {
92 namespace components {
94  public ExecutionObject, public LinkListener, public IEventListener,
95  public Thread {
96 
97  private:
98  static const short mSleepTime = 800;
99  set<FormatterLink*> links;
100  set<Link*> uncompiledLinks;
101 
102  set<FormatterEvent*> runningEvents; // child events occurring
103  set<FormatterEvent*> pausedEvents; // child events paused
104  short lastTransition;
105 
106  map<FormatterLink*, int> pendingLinks;
107  bool running;
108 
109  map<string, ExecutionObject*> execObjList;
110 
111  pthread_mutex_t compositeMutex;
112  pthread_mutex_t parentMutex;
113  pthread_mutex_t stlMutex;
114 
115  public:
117  string id,
118  Node *dataObject,
119  bool handling,
120  ILinkActionListener* seListener);
121 
123  string id,
124  Node *dataObject,
125  CascadingDescriptor *descriptor,
126  bool handling,
127  ILinkActionListener* seListener);
128 
129  virtual ~CompositeExecutionObject();
130 
131  protected:
132  void initializeCompositeExecutionObject(
133  string id,
134  Node *dataObject,
135  CascadingDescriptor *descriptor);
136 
137  public:
138  CompositeExecutionObject* getParentFromDataObject(Node* dataObject);
139  void suspendLinkEvaluation(bool suspend);
140  bool addExecutionObject(ExecutionObject *execObj);
141  bool containsExecutionObject(string execObjId);
142  ExecutionObject* getExecutionObject(string execObjId);
143  map<string, ExecutionObject*>* getExecutionObjects();
144  map<string, ExecutionObject*>* recursivellyGetExecutionObjects();
145  int getNumExecutionObjects();
146  bool removeExecutionObject(ExecutionObject* execObj);
147  set<Link*>* getUncompiledLinks();
148  bool containsUncompiledLink(Link* dataLink);
149  void removeLinkUncompiled(Link* ncmLink);
150  void setLinkCompiled(FormatterLink *formatterLink);
151  void addNcmLink(Link *ncmLink);
152  void removeNcmLink(Link *ncmLink);
153  void setAllLinksAsUncompiled(bool isRecursive);
154  void setParentsAsListeners();
155  void unsetParentsAsListeners();
156  void eventStateChanged(
157  void* event, short transition, short previousState);
158 
159  short getPriorityType();
160 
161  void linkEvaluationStarted(FormatterCausalLink *link);
162  void linkEvaluationFinished(FormatterCausalLink *link, bool start);
163 
164  bool setPropertyValue(AttributionEvent* event, string value);
165 
166  private:
167  void checkLinkConditions();
168  void run();
169  void listRunningObjects();
170  void listPendingLinks();
171 
172  void lockComposite();
173  void unlockComposite();
174 
175  void lockSTL();
176  void unlockSTL();
177  };
178 }
179 }
180 }
181 }
182 }
183 }
184 }
185 
186 #endif //_COMPOSITEEXECUTIONOBJECT_H_