Ginga  0.13.6
 All Classes Namespaces Functions Variables
DescriptorSwitch.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 _DESCRIPTORSWITCH_H_
51 #define _DESCRIPTORSWITCH_H_
52 
53 #include "../Entity.h"
54 using namespace ::br::pucrio::telemidia::ncl;
55 
56 #include "../descriptor/GenericDescriptor.h"
57 using namespace ::br::pucrio::telemidia::ncl::descriptor;
58 
59 #include "Rule.h"
60 
61 extern "C" {
62 #include <pthread.h>
63 }
64 
65 #include <string>
66 #include <iostream>
67 #include <vector>
68 using namespace std;
69 
70 namespace br {
71 namespace pucrio {
72 namespace telemidia {
73 namespace ncl {
74 namespace switches {
75  class DescriptorSwitch : public GenericDescriptor {
76  private:
77  vector<GenericDescriptor*>* descriptorList;
78  vector<Rule*>* ruleList;
79  GenericDescriptor* defaultDescriptor;
80  GenericDescriptor* selectedDescriptor;
81 
82  static set<DescriptorSwitch*> objects;
83  static bool initMutex;
84  static pthread_mutex_t _objMutex;
85 
86  static void addInstance(DescriptorSwitch* object);
87  static bool removeInstance(DescriptorSwitch* object);
88 
89  public:
90  DescriptorSwitch(string id);
91  virtual ~DescriptorSwitch();
92 
93  static bool hasInstance(
94  DescriptorSwitch* object, bool eraseFromList);
95 
96  bool addDescriptor(
97  unsigned int index,
98  GenericDescriptor* descriptor,
99  Rule* rule);
100 
101  bool addDescriptor(GenericDescriptor* descriptor, Rule* rule);
102  bool containsRule(Rule* rule);
103  void exchangeDescriptorsAndRules(
104  unsigned int index1,
105  unsigned int index2);
106 
107  int indexOfRule(Rule *rule);
108  GenericDescriptor* getDefaultDescriptor();
109  unsigned int indexOfDescriptor(GenericDescriptor* descriptor);
110  GenericDescriptor* getDescriptor(unsigned int index);
111  GenericDescriptor* getDescriptor(string descriptorId);
112  GenericDescriptor* getDescriptor(Rule* rule);
113  Rule* getRule(unsigned int index);
114  unsigned int getNumDescriptors();
115  unsigned int getNumRules();
116  bool removeDescriptor(unsigned int index);
117  bool removeDescriptor(GenericDescriptor* descriptor);
118  bool removeRule(Rule *rule);
119  void setDefaultDescriptor(GenericDescriptor* descriptor);
120  void select(GenericDescriptor* descriptor);
121  void selectDefault();
122  GenericDescriptor* getSelectedDescriptor();
123  };
124 }
125 }
126 }
127 }
128 }
129 
130 #endif //_DESCRIPTORSWITCH_H_