]> SALOME platform Git repositories - samples/dsccode.git/blob - src/DSCCODAENG/DSCCODAENG.cxx
Salome HOME
initial import into CVS
[samples/dsccode.git] / src / DSCCODAENG / DSCCODAENG.cxx
1 using namespace std;
2 #include "DSCCODAENG.hxx"
3 #include <string>
4 #include <unistd.h>
5
6 //! Constructor for component "DSCCODA" instance
7 /*!
8  *  
9  */
10 DSCCODA_i::DSCCODA_i(CORBA::ORB_ptr orb, 
11                      PortableServer::POA_ptr poa, 
12                      PortableServer::ObjectId * contId, 
13                      const char *instanceName, 
14                      const char *interfaceName) 
15           : Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
16 {
17   cout << "create component" << endl;
18   _thisObj = this ;
19   _id = _poa->activate_object(_thisObj);
20   _in_port=NULL;
21   _out_port=NULL;
22 }
23
24 //! Destructor for component "DSCCODA" instance
25 DSCCODA_i::~DSCCODA_i()
26 {
27 }
28
29 //! Register datastream ports for a component service given its name
30 /*!
31  *  \param service_name : service name
32  *  \return true if port registering succeeded, false if not
33  */
34 CORBA::Boolean
35 DSCCODA_i::init_service(const char * service_name) {
36   CORBA::Boolean rtn = false;
37   string s_name(service_name);
38   if (s_name == "prun") 
39     {
40       try
41         {
42           std::cerr << "DSCCODA: prun: uses "  << std::endl;
43           add_port("BASIC_short", "uses", "prun_out_port");
44           std::cerr << "DSCCODA: prun: provides "  << std::endl;
45           add_port("BASIC_short", "provides", "prun_in_port");
46         }
47       //catch(const PortAlreadyDefined& ex)
48       catch(PortAlreadyDefined ex)
49         {
50           std::cerr << "DSCCODA: deja defini" << ex.what() << std::endl;
51           //Ports already created : we use them
52         }
53       catch ( ... ) 
54         {
55           std::cerr << "DSCCODA: exception inconnue" << std::endl;
56         }
57
58       rtn = true;
59     }
60   if (s_name == "trun") 
61     {
62       try
63         {
64           std::cerr << "DSCCODA: trun: uses "  << std::endl;
65           add_port("BASIC_short", "uses", "trun_out_port");
66           std::cerr << "DSCCODA: trun: provides "  << std::endl;
67           add_port("BASIC_short", "provides", "trun_in_port");
68         }
69       catch(const PortAlreadyDefined& ex)
70         {
71           std::cerr << "DSCCODA: deja defini" << std::endl;
72           //Ports already created : we use them
73         }
74       catch ( ... ) 
75         {
76           std::cerr << "DSCCODA: exception inconnue" << std::endl;
77         }
78       rtn = true;
79     }
80   return rtn;
81 }
82
83 void DSCCODA_i::prun(CORBA::Long niter)
84 {
85   cout << "DSCCODA_i::prun" << endl;
86   uses_port * temp = NULL;
87   get_port(temp, "prun_out_port");
88   _out_port = dynamic_cast<data_short_port_uses *>(temp);
89   //get_port((uses_port*&)_out_port, "run_out_port");
90
91   provides_port * temp2 = NULL;
92   get_port(temp2, "prun_in_port");
93   _in_port = dynamic_cast<data_short_port_provides *>(temp2);
94
95   int j=0;
96   _out_port->put(j);
97   for(int i=0;i<niter;i++)
98     {
99       j=_in_port->get();
100       cout << "DSCCODA Got: " << j << endl;
101       usleep(100000);
102       j=j+5;
103       _out_port->put(j);
104     }
105 }
106 void DSCCODA_i::trun(CORBA::Long niter)
107 {
108   cout << "DSCCODA_i::trun" << endl;
109   uses_port * temp = NULL;
110   get_port(temp, "trun_out_port");
111   _out_port = dynamic_cast<data_short_port_uses *>(temp);
112   //get_port((uses_port*&)_out_port, "run_out_port");
113
114   provides_port * temp2 = NULL;
115   get_port(temp2, "trun_in_port");
116   _in_port = dynamic_cast<data_short_port_provides *>(temp2);
117
118   int j=0;
119   for(int i=0;i<niter;i++)
120     {
121       j=_in_port->get();
122       cout << "DSCCODA Got: " << j << endl;
123       usleep(100000);
124       j=j+5;
125       _out_port->put(j);
126     }
127 }
128
129 extern "C"
130 {
131   PortableServer::ObjectId * DSCCODAEngine_factory( CORBA::ORB_ptr orb, 
132                                                     PortableServer::POA_ptr poa, 
133                                                     PortableServer::ObjectId * contId,
134                                                     const char *instanceName, 
135                                                     const char *interfaceName)
136   {
137     MESSAGE("PortableServer::ObjectId * DSCCODAEngine_factory()");
138     DSCCODA_i * myEngine = new DSCCODA_i(orb, poa, contId, instanceName, interfaceName);
139     return myEngine->getId() ;
140   }
141 }