Ginga  0.13.6
 All Classes Namespaces Functions Variables
FormatterMediator.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 _FormatterMediator_H_
51 #define _FormatterMediator_H_
52 
53 #include "player/INCLPlayer.h"
54 #include "player/IApplicationPlayer.h"
55 #include "player/Player.h"
56 using namespace ::br::pucrio::telemidia::ginga::core::player;
57 
58 #include "ncl/components/ContextNode.h"
59 #include "ncl/components/CompositeNode.h"
60 #include "ncl/components/ContentNode.h"
61 #include "ncl/components/Node.h"
62 #include "ncl/components/NodeEntity.h"
63 using namespace ::br::pucrio::telemidia::ncl::components;
64 
65 #include "ncl/interfaces/Anchor.h"
66 #include "ncl/interfaces/PropertyAnchor.h"
67 #include "ncl/interfaces/Port.h"
68 #include "ncl/interfaces/SwitchPort.h"
69 #include "ncl/interfaces/InterfacePoint.h"
70 using namespace ::br::pucrio::telemidia::ncl::interfaces;
71 
72 #include "system/compat/SystemCompat.h"
73 using namespace ::br::pucrio::telemidia::ginga::core::system::compat;
74 
75 #include "ncl/switches/Rule.h"
76 using namespace ::br::pucrio::telemidia::ncl::switches;
77 
78 #include "ncl/descriptor/GenericDescriptor.h"
79 using namespace ::br::pucrio::telemidia::ncl::descriptor;
80 
81 #include "ncl/link/Bind.h"
82 #include "ncl/link/CausalLink.h"
83 #include "ncl/link/Link.h"
84 using namespace ::br::pucrio::telemidia::ncl::link;
85 
86 #include "ncl/connectors/EventUtil.h"
87 #include "ncl/connectors/SimpleAction.h"
88 #include "ncl/connectors/Connector.h"
89 using namespace ::br::pucrio::telemidia::ncl::connectors;
90 
91 #include "ncl/layout/LayoutRegion.h"
92 using namespace ::br::pucrio::telemidia::ncl::layout;
93 
94 #include "ncl/reuse/ReferNode.h"
95 using namespace ::br::pucrio::telemidia::ncl::reuse;
96 
97 #include "util/functions.h"
98 using namespace ::br::pucrio::telemidia::util;
99 
100 #include "ncl/Base.h"
101 #include "ncl/NclDocument.h"
102 #include "ncl/connectors/ConnectorBase.h"
103 #include "ncl/descriptor/DescriptorBase.h"
104 #include "ncl/layout/RegionBase.h"
105 #include "ncl/switches/RuleBase.h"
106 using namespace ::br::pucrio::telemidia::ncl;
107 
108 #include "ncl/transition/Transition.h"
109 #include "ncl/transition/TransitionBase.h"
110 using namespace ::br::pucrio::telemidia::ncl::transition;
111 
112 #include "model/CompositeExecutionObject.h"
113 #include "model/ExecutionObject.h"
114 #include "model/NodeNesting.h"
115 using namespace ::br::pucrio::telemidia::ginga::ncl::model::components;
116 
117 #include "model/FormatterEvent.h"
118 #include "model/AttributionEvent.h"
119 using namespace ::br::pucrio::telemidia::ginga::ncl::model::event;
120 
121 #include "model/ILinkActionListener.h"
122 #include "model/LinkAssignmentAction.h"
123 using namespace ::br::pucrio::telemidia::ginga::ncl::model::link;
124 
125 #include "adaptation/context/RuleAdapter.h"
126 using namespace ::br::pucrio::telemidia::ginga::ncl::adaptation::context;
127 
128 #include "emconverter/ObjectCreationForbiddenException.h"
129 #include "emconverter/FormatterConverter.h"
130 using namespace ::br::pucrio::telemidia::ginga::ncl::emconverter;
131 
132 #include "prefetch/IPrefetchManager.h"
133 using namespace ::br::pucrio::telemidia::ginga::ncl::prefetch;
134 
135 #include "FormatterScheduler.h"
136 #include "privatebase/PrivateBaseManager.h"
137 
138 #include <map>
139 #include <set>
140 #include <vector>
141 #include <string>
142 using namespace std;
143 
144 namespace br {
145 namespace pucrio {
146 namespace telemidia {
147 namespace ginga {
148 namespace ncl {
149  class EntryEventListener : public IEventListener {
150  private:
151  Player* player;
152  set<FormatterEvent*> events;
153  int eventsRunning;
154  bool hasStartPoint;
155  pthread_mutex_t evMutex;
156 
157  public:
158  EntryEventListener(Player* player, string interfaceId);
159  virtual ~EntryEventListener();
160 
161  virtual void listenEvent(FormatterEvent* event);
162  virtual void eventStateChanged(
163  void* event, short transition, short previousState);
164 
165  short getPriorityType();
166  };
167 
168  class FormatterMediator : public INCLPlayer, public Player,
170 
171  private:
172  EntryEventListener* entryEventListener;
173  NclPlayerData* data;
174  string currentFile;
175  NclDocument* currentDocument;
176 
177  PrivateBaseManager* privateBaseManager;
178  static IPrefetchManager* pm;
179  map<string, FormatterEvent*> documentEvents;
180  map<string, vector<FormatterEvent*>*> documentEntryEvents;
181  map<Port*, FormatterEvent*> portsToEntryEvents;
182  FormatterScheduler* scheduler;
183  RuleAdapter* ruleAdapter;
184  FormatterConverter* compiler;
185  PlayerAdapterManager* playerManager;
186  ITimeBaseProvider* timeBaseProvider;
187  vector<string> compileErrors;
188  IDeviceLayout* deviceLayout;
189  IFormatterMultiDevice* multiDevice;
190  PresentationContext* presContext;
191  bool isEmbedded;
192  bool enablePrefetch;
193  bool docCompiled;
194  pthread_mutex_t pteMutex;
195 
196  public:
198  virtual ~FormatterMediator();
199 
200  static void release();
201 
202  void printGingaWindows();
203  set<string>* createPortIdList();
204  short getMappedInterfaceType(string portId);
205 
206  void setMrl(string mrl, bool visible=true);
207  void reset(){};
208  void rebase(){};
209  void printData(NclPlayerData* data);
210  //void setStandByState(bool standBy);
211  void setTimeBaseProvider(ITimeBaseProvider* timeBaseProvider);
212 
213  void setBackgroundImage(string uri);
214  void setParentLayout(void* parentLayout);
215  string getScreenShot();
216 
217  vector<string>* getCompileErrors();
218  void* setCurrentDocument(string fName);
219 
220  private:
221  virtual void* addDocument(string fName);
222  bool removeDocument(string documentId);
223  ContextNode* getDocumentContext(string documentId);
224 
225  public:
226  void setDepthLevel(int level);
227  int getDepthLevel();
228 
229  Port* getPortFromEvent(FormatterEvent* event);
230 
231  private:
232  vector<Port*>* getContextPorts(
233  ContextNode* context, string interfaceId);
234 
235  vector<FormatterEvent*>* processDocument(
236  string documentId, string interfaceId);
237 
238  void initializeSettingNodes(Node* node);
239 
240  vector<FormatterEvent*>* getDocumentEntryEvent(string documentId);
241 
242  bool compileDocument(string documentId);
243  bool prepareDocument(string documentId);
244 
245  void solveRemoteDescriptorsUris(string docLocation,
246  vector<GenericDescriptor*>* descs, bool isRemoteDoc);
247 
248  void solveRemoteNodesUris(
249  string docLocation, vector<Node*>* nodes, bool isRemoteDoc);
250 
251  void solveRemoteNclDeps(string docLocation, bool isRemoteDoc);
252 
253  void solveRemoteLuaDeps(
254  string docLocation, string src, bool isRemoteDoc);
255 
256  string solveRemoteSourceUri(string docLocation, string src);
257 
258  FormatterEvent* getEntryEvent(
259  string interfaceId, vector<FormatterEvent*>* events);
260 
261  bool startDocument(string documentId, string interfaceId);
262  bool stopDocument(string documentId);
263  bool pauseDocument(string documentId);
264  bool resumeDocument(string documentId);
265  void presentationCompleted(IFormatterEvent* documentEvent);
266 
267  public:
268  bool nclEdit(string nclEditApi);
269  bool editingCommand(string commandTag, string privateDataPayload);
270 
271  private:
272  LayoutRegion* addRegion(
273  string documentId,
274  string regionBaseId,
275  string regionId,
276  string xmlRegion);
277 
278  LayoutRegion* removeRegion(
279  string documentId,
280  string regionBaseId,
281  string regionId);
282 
283  RegionBase* addRegionBase(string documentId, string xmlRegionBase);
284  RegionBase* removeRegionBase(
285  string documentId, string regionBaseId);
286 
287  Rule* addRule(string documentId, string xmlRule);
288  Rule* removeRule(string documentId, string ruleId);
289  RuleBase* addRuleBase(string documentId, string xmlRuleBase);
290  RuleBase* removeRuleBase(string documentId, string ruleBaseId);
291  Transition* addTransition(string documentId, string xmlTransition);
292  Transition* removeTransition(
293  string documentId, string transitionId);
294 
295  TransitionBase* addTransitionBase(
296  string documentId, string xmlTransitionBase);
297 
298  TransitionBase* removeTransitionBase(
299  string documentId, string transitionBaseId);
300 
301  Connector* addConnector(string documentId, string xmlConnector);
302  Connector* removeConnector(string documentId, string connectorId);
303  ConnectorBase* addConnectorBase(
304  string documentId, string xmlConnectorBase);
305 
306  ConnectorBase* removeConnectorBase(
307  string documentId, string connectorBaseId);
308 
309  GenericDescriptor* addDescriptor(
310  string documentId, string xmlDescriptor);
311 
312  GenericDescriptor* removeDescriptor(
313  string documentId, string descriptorId);
314 
315  DescriptorBase* addDescriptorBase(
316  string documentId, string xmlDescriptorBase);
317 
318  DescriptorBase* removeDescriptorBase(
319  string documentId, string descriptorBaseId);
320 
321  Base* addImportBase(
322  string documentId, string docBaseId, string xmlImportBase);
323 
324  Base* removeImportBase(
325  string documentId, string docBaseId, string documentURI);
326 
327  NclDocument* addImportedDocumentBase(
328  string documentId, string xmlImportedDocumentBase);
329 
330  NclDocument* removeImportedDocumentBase(
331  string documentId, string importedDocumentBaseId);
332 
333  NclDocument* addImportNCL(string documentId, string xmlImportNCL);
334  NclDocument* removeImportNCL(string documentId, string documentURI);
335 
336  void processInsertedReferNode(ReferNode* referNode);
337  void processInsertedComposition(CompositeNode* composition);
338 
339  Node* addNode(
340  string documentId, string compositeId, string xmlNode);
341 
342  Node* removeNode(
343  string documentId, string compositeId, string nodeId);
344 
345  InterfacePoint* addInterface(
346  string documentId, string nodeId, string xmlInterface);
347 
348  void removeInterfaceMappings(
349  Node* node,
350  InterfacePoint* interfacePoint,
351  CompositeNode* composition);
352 
353  void removeInterfaceLinks(
354  Node* node,
355  InterfacePoint* interfacePoint,
356  ContextNode* composition);
357 
358  void removeInterface(
359  Node* node, InterfacePoint* interfacePoint);
360 
361  InterfacePoint* removeInterface(
362  string documentId, string nodeId, string interfaceId);
363 
364  Link* addLink(
365  string documentId, string compositeId, string xmlLink);
366 
367  void removeLink(ContextNode* composition, Link* link);
368 
369  Link* removeLink(
370  string documentId, string compositeId, string linkId);
371 
372  bool setPropertyValue(
373  string documentId,
374  string nodeId,
375  string propertyId,
376  string value);
377 
378  public:
379  void setNotifyContentUpdate(bool notify){};
380  void addListener(IPlayerListener* listener);
381  void removeListener(IPlayerListener* listener);
382  void notifyPlayerListeners(
383  short code, string paremeter, short type, string value);
384 
385  void setSurface(ISurface* surface);
386  ISurface* getSurface();
387  void flip();
388  double getMediaTime();
389  double getTotalMediaTime();
390  void setMediaTime(double newTime);
391  bool setKeyHandler(bool isHandler);
392  void setScope(
393  string scope,
394  short type,
395  double begin=-1, double end=-1, double outTransDur=-1);
396 
397  bool play();
398  void stop();
399  void abort();
400  void pause();
401  void resume();
402 
403  string getPropertyValue(string name);
404  void setPropertyValue(string name, string value);
405 
406  void setReferenceTimePlayer(IPlayer* player);
407  void addTimeReferPlayer(IPlayer* referPlayer);
408  void removeTimeReferPlayer(IPlayer* referPlayer);
409  void notifyReferPlayers(int transition);
410  void timebaseObjectTransitionCallback(int transition);
411  void setTimeBasePlayer(IPlayer* timeBasePlayer);
412  bool hasPresented();
413  void setPresented(bool presented);
414  bool isVisible();
415  void setVisible(bool visible);
416  bool immediatelyStart();
417  void setImmediatelyStart(bool immediatelyStartVal);
418  void forceNaturalEnd(bool forceIt);
419  bool isForcedNaturalEnd();
420  bool setOutWindow(GingaWindowID windowId);
421 
422  /*Exclusive for ChannelPlayer*/
423  IPlayer* getSelectedPlayer() {return NULL;};
424  void setPlayerMap(map<string, IPlayer*>* objs){};
425  map<string, IPlayer*>* getPlayerMap() {return NULL;};
426  IPlayer* getPlayer(string objectId) {return NULL;};
427  void select(IPlayer* selObject){};
428 
429  /*Exclusive for Application Players*/
430  void setCurrentScope(string scopeId);
431 
432  string getActiveUris(vector<string>* uris);
433  string getDepUris(vector<string>* uris, int targetDev=0);
434 
435  /* */
436  IPresentationContext* getPresentationContext();
437 
438  private:
439  string getDepUrisFromNodes(
440  vector<string>* uris, vector<Node*>* nodes, int targetDev=0);
441 
442  string getDepUriFromNode(
443  vector<string>* uris, Node* node, int targetDev=0);
444 
445  string getBaseUri(string baseA, string baseB);
446 
447  public:
448  void timeShift(string direction);
449  };
450 }
451 }
452 }
453 }
454 }
455 
456 #endif //_FormatterMediator_H_
Definition: IFormatterSchedulerListener.h:61
Definition: Player.h:249
Definition: FormatterMediator.h:168
Definition: FormatterScheduler.h:136
Definition: INCLPlayer.h:63