]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/Test/TestComponent.cxx
Salome HOME
Update copyrights 2014.
[modules/yacs.git] / src / runtime / Test / TestComponent.cxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "Any.hxx"
21 #include <iostream>
22 #include <cstring>
23 #include <cmath>
24 #include "TestComponent.hxx"
25
26
27 extern "C" void * __init()
28 {
29         TestComponent * obj = new TestComponent();
30         obj->info.code = 0;
31         obj->info.message = "";
32         return obj;
33 }
34  
35 extern "C" void __terminate(void **pObj)
36 {
37         TestComponent * obj = * (TestComponent **) pObj;
38         delete obj;
39         *pObj = NULL;
40 }
41
42 extern "C" void __ping()
43 {
44         std::cerr << "ping TestComponent" << std::endl;
45 }
46     
47 extern "C" void __run(void *vObj, const char *service, int nIn, int nOut, 
48                          YACS::ENGINE::Any **In, YACS::ENGINE::Any **Out, returnInfo * r)
49 {
50         TestComponent * obj = (TestComponent *) vObj;
51         
52         if (obj == NULL) {
53                 r->code = -1;
54                 r->message = "TestComponent has not been initialized";
55                 return;
56         }
57         
58         obj->info.message = "";
59         obj->info.code = 0;
60         
61         if (std::strncmp(service, "f", 1) == 0) 
62         {
63                 double _arg0 = In[0]->getDoubleValue();
64                 double _res = obj->f(_arg0);
65                 Out[0] = YACS::ENGINE::AtomAny::New(_res);
66         }
67         else
68         {
69                 obj->info.code = 1;
70                 obj->info.message = "service ";
71                 obj->info.message += service;
72                 obj->info.message += " doesn't exist in TestComponent";
73                 Out[0] = NULL;
74         }
75         *r = obj->info;
76 }
77
78 double TestComponent::f(double x)
79 {
80         double y;
81         
82         if (x >= 0.0)
83         {
84           y = std::sqrt(x);
85         }
86         else {
87           y = 0.0;
88           info.message = "TestComponent::f : argument must be positive or null";
89           info.code = 2;
90         }
91         return y;
92 }
93
94 double TestComponent::g(int n, double x)
95 {
96         double y;
97         y = std::pow(x, n);
98         return y;
99 }