7 #include <CalciumInterface.hxx>
10 //! Constructor for component "INTERPK" instance
14 INTERPK_i::INTERPK_i(CORBA::ORB_ptr orb,
15 PortableServer::POA_ptr poa,
16 PortableServer::ObjectId * contId,
17 const char *instanceName,
18 const char *interfaceName)
19 : Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
21 cerr << "create component" << endl;
23 _id = _poa->activate_object(_thisObj);
26 //! Destructor for component "INTERPK" instance
27 INTERPK_i::~INTERPK_i()
31 //! Register datastream ports for a component service given its name
33 * \param service_name : service name
34 * \return true if port registering succeeded, false if not
37 INTERPK_i::init_service(const char * service_name) {
38 CORBA::Boolean rtn = false;
39 string s_name(service_name);
44 std::cerr << "INTERPK: prun: " << std::endl;
45 //initialization CALCIUM ports IN
46 calcium_real_port_provides * p1;
47 p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","tparoi");
48 p1->setDependencyType(CalciumTypes::ITERATION_DEPENDENCY);
49 //initialization CALCIUM ports OUT
50 add_port<calcium_real_port_uses>("CALCIUM_real","uses","tpar");
52 catch(const PortAlreadyDefined& ex)
54 std::cerr << "INTERPK: " << ex.what() << std::endl;
55 //Ports already created : we use them
59 std::cerr << "INTERPK: unknown exception" << std::endl;
68 std::cerr << "INTERPK: trun: " << std::endl;
69 //initialization CALCIUM ports IN
70 calcium_real_port_provides * p1;
71 p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","tparoit");
72 p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
73 calcium_integer_port_provides * p2;
74 p2 = add_port<calcium_integer_port_provides>("CALCIUM_integer","provides","topo");
75 p2->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
77 //initialization CALCIUM ports OUT
78 add_port<calcium_real_port_uses>("CALCIUM_real","uses","tpart");
79 add_port<calcium_integer_port_uses>("CALCIUM_integer","uses","stopo");
81 catch(const PortAlreadyDefined& ex)
83 std::cerr << "INTERPK: " << ex.what() << std::endl;
84 //Ports already created : we use them
88 std::cerr << "INTERPK: unknown exception" << std::endl;
95 void INTERPK_i::perma(Superv_Component_i * component)
97 float t=0.,tparoi[100],tp[100];
101 info=cp_lre(component,CP_SEQUENTIEL,&t,&t,&ii,(char*)"tparoi",100,&nval,tparoi);
103 for(int i=0;i<nval;i++)
105 printf("INTERPK:iteration= %d\n",ii);
106 info=cp_ere(component,CP_TEMPS, t, ii, (char*)"tpar", nval, tp);
109 cp_fin(component,CP_ARRET);
112 void INTERPK_i::prun()
114 std::cerr << "INTERPK_i::prun" << std::endl;
115 beginService("INTERPK_i::prun");
116 Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
117 char nom_instance[INSTANCE_LEN];
118 int info = cp_cd(component,nom_instance);
123 catch ( const CalciumException & ex)
125 std::cerr << ex.what() << std::endl;
126 cp_fin(component,CP_ARRET);
130 std::cerr << "unexpected exception" << std::endl;
131 cp_fin(component,CP_ARRET);
133 endService("INTERPK_i::prun");
134 std::cerr << "end of INTERPK_i::prun" << std::endl;
137 void INTERPK_i::transit(Superv_Component_i * component)
139 float t=0.,tparoi[100],tp[100];
140 int topo[20],stopo[20];
141 int ii,nval,info,mval;
142 for(int i=0;i<20;i++)
147 info=cp_lre(component,CP_SEQUENTIEL,&t,&t,&ii,(char*)"tparoit",100,&nval,tparoi);
149 for(int i=0;i<nval;i++)
151 info=cp_len(component,CP_SEQUENTIEL,&t,&t,&ii,(char*)"topo",20,&mval,topo);
154 printf("INTERPK:temps= %f\n",t);
155 for(int i=0;i<mval;i++)
157 stopo[i]=stopo[i]+topo[i];
158 printf("stopo[%d]=%d;",i,stopo[i]);
162 info=cp_ere(component,CP_TEMPS, t, ii, (char*)"tpart", nval, tp);
164 info=cp_een(component,CP_TEMPS, t, ii, (char*)"stopo", mval, stopo);
167 cp_fin(component,CP_ARRET);
170 void INTERPK_i::trun()
172 std::cerr << "INTERPK_i::trun" << std::endl;
173 beginService("INTERPK_i::trun");
174 Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
175 char nom_instance[INSTANCE_LEN];
176 int info = cp_cd(component,nom_instance);
181 catch ( const CalciumException & ex)
183 std::cerr << ex.what() << std::endl;
184 cp_fin(component,CP_ARRET);
188 std::cerr << "unexpected exception" << std::endl;
189 cp_fin(component,CP_ARRET);
191 endService("INTERPK_i::trun");
192 std::cerr << "end of INTERPK_i::trun" << std::endl;
197 PortableServer::ObjectId * INTERPKEngine_factory( CORBA::ORB_ptr orb,
198 PortableServer::POA_ptr poa,
199 PortableServer::ObjectId * contId,
200 const char *instanceName,
201 const char *interfaceName)
203 std::cerr << "INTERPKEngine_factory" << std::endl;
204 INTERPK_i * myEngine = new INTERPK_i(orb, poa, contId, instanceName, interfaceName);
205 return myEngine->getId() ;