summaryrefslogtreecommitdiffstats
path: root/tags/native-sca-1.0.incubating-M3/runtime/core/src/tuscany/sca/core/Operation.h
blob: 89cf0b63b70e9724ba3ff8a052e51f0958249f5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/* $Rev$ $Date$ */

#ifndef tuscany_sca_core_operation_h
#define tuscany_sca_core_operation_h

#include <string>
#include <vector>

#include "commonj/sdo/SDO.h"

#include "tuscany/sca/export.h"


namespace tuscany
{
    namespace sca
    {
        /**
         * Holds the details of a single invocation of a business method.
         * This class is used to pass the parameters and operation name from the
         * client to a service. It will also hold the return value on the 
         * return from the business method.
         */
        class Operation 
        {
        public:
            /**
             * Create a new operation.
             * @param operationName The method name of the business method to be invoked.
             * @param numParameters The number of parameters to be passed.
             */
            SCA_API Operation(const char* operationName = 0);

            /**
             * Destructor.
             */
            SCA_API virtual    ~Operation();

            /**
             * Copy constructor.
             */
            SCA_API Operation(const Operation& op);

            /**
             * Assignment operator.
             */
            SCA_API Operation& operator=(const Operation& op);

            /**
             * Return the operation name.
             * @return The name of the operation.
             */
            SCA_API const std::string& getName() const {return name;}


            enum ParameterType
            {
            	UNSET = 0,
                VOID_TYPE,
                BOOL,
                SHORT,
                INT,
                LONG,
                USHORT,
                UINT,
                ULONG,
                FLOAT,
                DOUBLE,
                LONGDOUBLE,
                CHARS,
                CHAR,
                STRING,
                DATAOBJECT
            };

            class Parameter
            {
                public:
                    SCA_API Parameter(void* value = NULL, ParameterType type = VOID_TYPE, const std::string& name = "");
                    SCA_API void* getValue() const {return value;}
                    SCA_API ParameterType getType() const {return type;}
                    SCA_API const std::string& getName() const {return name;}
                    SCA_API bool hasName() const {return (name.length() > 0);}

                private:
                    std::string name;
                    void* value;
                    ParameterType type;
            };

            /**
             * Set a return value for the operation.
             * @param retVal Pointer to the return value.
             */
            SCA_API void setReturnValue(const void *retVal);
            SCA_API void setReturnValue(const bool *retVal);
            SCA_API void setReturnValue(const short *retVal);
            SCA_API void setReturnValue(const int *retVal);
            SCA_API void setReturnValue(const long *retVal);
            SCA_API void setReturnValue(const unsigned short *retVal);
            SCA_API void setReturnValue(const unsigned int *retVal);
            SCA_API void setReturnValue(const unsigned long *retVal);
            SCA_API void setReturnValue(const float *retVal);
            SCA_API void setReturnValue(const double *retVal);
            SCA_API void setReturnValue(const long double *retVal);
            SCA_API void setReturnValue(const char *retVal);
            SCA_API void setReturnValue(const char* *retVal);
            SCA_API void setReturnValue(const std::string *retVal);
            SCA_API void setReturnValue(const commonj::sdo::DataObjectPtr *retVal);

            /**
             * Set a parameter on the operation.
             * @param parm Pointer to the parameter to be passed.
             */
            SCA_API void addParameter(const void *parm);
            SCA_API void addParameter(const bool *parm);
            SCA_API void addParameter(const short *parm);
            SCA_API void addParameter(const int *parm);
            SCA_API void addParameter(const long *parm);
            SCA_API void addParameter(const unsigned short *parm);
            SCA_API void addParameter(const unsigned int *parm);
            SCA_API void addParameter(const unsigned long *parm);
            SCA_API void addParameter(const float *parm);
            SCA_API void addParameter(const double *parm);
            SCA_API void addParameter(const long double *parm);
            SCA_API void addParameter(const char *parm);
            SCA_API void addParameter(const char* *parm);
            SCA_API void addParameter(const std::string *parm);
            SCA_API void addParameter(const commonj::sdo::DataObjectPtr *parm);

            /**
             * Set a parameter on the operation.
             * @param name The name of the parameter in the parameter list.
             * @param parm Pointer to the parameter to be passed.
             */
            SCA_API void addParameter(const std::string& name, const void *parm);
            SCA_API void addParameter(const std::string& name, const bool *parm);
            SCA_API void addParameter(const std::string& name, const short *parm);
            SCA_API void addParameter(const std::string& name, const int *parm);
            SCA_API void addParameter(const std::string& name, const long *parm);
            SCA_API void addParameter(const std::string& name, const unsigned short *parm);
            SCA_API void addParameter(const std::string& name, const unsigned int *parm);
            SCA_API void addParameter(const std::string& name, const unsigned long *parm);
            SCA_API void addParameter(const std::string& name, const float *parm);
            SCA_API void addParameter(const std::string& name, const double *parm);
            SCA_API void addParameter(const std::string& name, const long double *parm);
            SCA_API void addParameter(const std::string& name, const char *parm);
            SCA_API void addParameter(const std::string& name, const char* *parm);
            SCA_API void addParameter(const std::string& name, const std::string *parm);
            SCA_API void addParameter(const std::string& name, const commonj::sdo::DataObjectPtr *parm);
            
            SCA_API unsigned int getNParms() const {return parameters.size();}

            /**
             * Get a parameter from the operation.
             * @param pos The position of the parameter in the parameter list.
             * @return Pointer to the paramter at the given postion. Should be
             * cast to the appropriate type.
             */
            SCA_API const Parameter& getParameter(unsigned int pos) const;

            /**
             * Get a parameter from the operation.
             * @param name The name of the parameter in the parameter list.
             * @return Pointer to the paramter with the given name. Should be
             * cast to the appropriate type.
             */
            SCA_API const Parameter& getParameter(const std::string& name) const;

            /**
             * Get a parameter type from the operation.
             * @param pos The position of the parameter in the parameter list.
             * @return Type of the parameter at the given position.
             */
            SCA_API ParameterType getParameterType(unsigned int pos) const;

            /**
             * Get a parameter type from the operation.
             * @param name The name of the parameter in the parameter list.
             * @return Type of the parameter with the given name.
             */
            SCA_API ParameterType getParameterType(const std::string& name) const;

            /**
             * Get a parameter name from the operation.
             * @param pos The position of the parameter in the parameter list.
             * @return Name of the parameter at the given position.
             */
            SCA_API const std::string& getParameterName(unsigned int pos) const;

            /**
             * Get the parameter value from the operation.
             * @param pos The position of the parameter in the parameter list.
             * @return Pointer to the value of the parameter at the given postion. Should be
             * cast to the appropriate type.
             */
            SCA_API void* getParameterValue(unsigned int pos) const;

            /**
             * Get the parameter value from the operation.
             * @param name The name of the parameter in the parameter list.
             * @return Pointer to the value of the parameter with the given name. Should be
             * cast to the appropriate type.
             */
            SCA_API void* getParameterValue(const std::string& name) const;

            SCA_API ParameterType getReturnType() const {return returnValue.getType();}
            SCA_API void* getReturnValue() const {return returnValue.getValue();}

        private:
            /**
             * Operation name (method name).
             */ 
            std::string name;

            /**
             * Array of parameters.
             */
            typedef std::vector<Parameter> PARAMETER_VECTOR;
            
            PARAMETER_VECTOR parameters;

            Parameter returnValue;
            
            void clean();
            void copy(const Operation& op);

        };
    } // End namespace sca
} // End namespace tuscany

#endif // tuscany_sca_core_operation_h