| 1 | /* | |
| 2 | * Copyright 1999-2006 University of Chicago | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | ||
| 17 | ||
| 18 | #include "CounterService_skeleton.h" | |
| 19 | #include "CounterService_internal_skeleton.h" | |
| 20 | ||
| 21 | #include "globus_wsrf_resource.h" | |
| 22 | #include "globus_wsrf_core_tools.h" | |
| 23 | #include "globus_soap_message_handle.h" | |
| 24 | ||
| 25 | extern globus_service_descriptor_t CounterService_descriptor; | |
| 26 | ||
| 27 | ||
| 28 | globus_result_t | |
| 29 | CounterService_init( | |
| 30 | globus_service_descriptor_t * service_desc) | |
| 31 | 3 | { |
| 32 | 3 | int rc; |
| 33 | ||
| 34 | 3 | GlobusFuncName(CounterService_init); |
| 35 | 3 | CounterServiceDebugEnter(); |
| 36 | ||
| 37 | 3 | rc = globus_module_activate(GLOBUS_WSRF_RESOURCE_MODULE); |
| 38 | ||
| 39 | 3 | CounterServiceDebugExit(); |
| 40 | ||
| 41 | 3 | return (rc == GLOBUS_SUCCESS) ? GLOBUS_SUCCESS : GLOBUS_FAILURE; |
| 42 | } | |
| 43 | ||
| 44 | globus_result_t | |
| 45 | CounterService_finalize( | |
| 46 | globus_service_descriptor_t * service_desc) | |
| 47 | 0 | { |
| 48 | 0 | int rc; |
| 49 | 0 | GlobusFuncName(CounterService_finalize); |
| 50 | ||
| 51 | 0 | CounterServiceDebugEnter(); |
| 52 | ||
| 53 | /* do any service specific finalize stuff here, | |
| 54 | * opposite of CounterService_init | |
| 55 | */ | |
| 56 | ||
| 57 | 0 | rc = globus_module_deactivate(GLOBUS_WSRF_RESOURCE_MODULE); |
| 58 | ||
| 59 | 0 | CounterServiceDebugExit(); |
| 60 | ||
| 61 | 0 | return (rc == GLOBUS_SUCCESS) ? GLOBUS_SUCCESS : GLOBUS_FAILURE; |
| 62 | } | |
| 63 | ||
| 64 | /* these functions are the service implementation and | |
| 65 | * must be implemented by the service implementer | |
| 66 | */ | |
| 67 | ||
| 68 | globus_result_t | |
| 69 | CounterPortType_GetCurrentMessage_impl( | |
| 70 | globus_service_engine_t engine, | |
| 71 | globus_soap_message_handle_t message, | |
| 72 | globus_service_descriptor_t * service, | |
| 73 | wsnt_GetCurrentMessageType * GetCurrentMessage, | |
| 74 | wsnt_GetCurrentMessageResponseType * GetCurrentMessageResponse, | |
| 75 | const char ** fault_name, | |
| 76 | void ** fault) | |
| 77 | 0 | { |
| 78 | /* add function local variable declarations here */ | |
| 79 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 80 | ||
| 81 | /* initialize trace debugging info */ | |
| 82 | 0 | GlobusFuncName(CounterPortType_GetCurrentMessage_impl); |
| 83 | 0 | CounterServiceDebugEnter(); |
| 84 | ||
| 85 | /* This is where it all happens. Service implementer must | |
| 86 | * implmenent this function. Asume that GetCurrentMessage has | |
| 87 | * been initialized and filled with request values. | |
| 88 | * GetCurrentMessageResponse must be set by the implementer. | |
| 89 | */ | |
| 90 | ||
| 91 | 0 | result = CounterServiceErrorNotImplemented( |
| 92 | "CounterPorType_GetCurrentMessage_impl"); | |
| 93 | ||
| 94 | 0 | CounterServiceDebugExit(); |
| 95 | 0 | return result; |
| 96 | } | |
| 97 | ||
| 98 | ||
| 99 | ||
| 100 | /* these functions are the service implementation and | |
| 101 | * must be implemented by the service implementer | |
| 102 | */ | |
| 103 | ||
| 104 | ||
| 105 | globus_result_t | |
| 106 | CounterPortType_Subscribe_impl( | |
| 107 | globus_service_engine_t engine, | |
| 108 | globus_soap_message_handle_t message, | |
| 109 | globus_service_descriptor_t * service, | |
| 110 | wsnt_SubscribeType * Subscribe, | |
| 111 | wsnt_SubscribeResponseType * SubscribeResponse, | |
| 112 | const char ** fault_name, | |
| 113 | void ** fault) | |
| 114 | 0 | { |
| 115 | /* add function local variable declarations here */ | |
| 116 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 117 | ||
| 118 | /* initialize trace debugging info */ | |
| 119 | 0 | GlobusFuncName(CounterPortType_Subscribe_impl); |
| 120 | 0 | CounterServiceDebugEnter(); |
| 121 | ||
| 122 | /* This is where it all happens. Service implementer must | |
| 123 | * implmenent this function. Asume that Subscribe has | |
| 124 | * been initialized and filled with request values. | |
| 125 | * SubscribeResponse must be set by the implementer. | |
| 126 | */ | |
| 127 | ||
| 128 | 0 | result = CounterServiceErrorNotImplemented( |
| 129 | "CounterPortType_Subscribe_impl"); | |
| 130 | ||
| 131 | 0 | CounterServiceDebugExit(); |
| 132 | 0 | return result; |
| 133 | } | |
| 134 | ||
| 135 | /* these functions are the service implementation and | |
| 136 | * must be implemented by the service implementer | |
| 137 | */ | |
| 138 | ||
| 139 | ||
| 140 | globus_result_t | |
| 141 | CounterPortType_GetMultipleResourceProperties_impl( | |
| 142 | globus_service_engine_t engine, | |
| 143 | globus_soap_message_handle_t message, | |
| 144 | globus_service_descriptor_t * service, | |
| 145 | wsrp_GetMultipleResourcePropertiesType * GetResourceProperty, | |
| 146 | wsrp_GetMultipleResourcePropertiesResponseType * GetMultipleResourcePropertiesResponse, | |
| 147 | const char ** fault_name, | |
| 148 | void ** fault) | |
| 149 | 0 | { |
| 150 | /* add function local variable declarations here */ | |
| 151 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 152 | ||
| 153 | /* initialize trace debugging info */ | |
| 154 | 0 | GlobusFuncName(CounterPortType_GetMultipleResourceProperties_impl); |
| 155 | 0 | CounterServiceDebugEnter(); |
| 156 | ||
| 157 | /* This is where it all happens. Service implementer must | |
| 158 | * implmenent this function. Asume that GetResourceProperty has | |
| 159 | * been initialized and filled with request values. | |
| 160 | * GetResourcePropertyResponse must be set by the implementer. | |
| 161 | */ | |
| 162 | ||
| 163 | 0 | result = CounterServiceErrorNotImplemented( |
| 164 | "CounterPortType_GetMultipleResourceProperties_impl"); | |
| 165 | ||
| 166 | 0 | CounterServiceDebugExit(); |
| 167 | 0 | return result; |
| 168 | } | |
| 169 | ||
| 170 | ||
| 171 | ||
| 172 | /* these functions are the service implementation and | |
| 173 | * must be implemented by the service implementer | |
| 174 | */ | |
| 175 | ||
| 176 | ||
| 177 | globus_result_t | |
| 178 | CounterPortType_GetResourceProperty_impl( | |
| 179 | globus_service_engine_t engine, | |
| 180 | globus_soap_message_handle_t message, | |
| 181 | globus_service_descriptor_t * service, | |
| 182 | xsd_QName * GetResourceProperty, | |
| 183 | wsrp_GetResourcePropertyResponseType * GetResourcePropertyResponse, | |
| 184 | const char ** fault_name, | |
| 185 | void ** fault) | |
| 186 | 0 | { |
| 187 | /* add function local variable declarations here */ | |
| 188 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 189 | ||
| 190 | /* initialize trace debugging info */ | |
| 191 | 0 | GlobusFuncName(CounterPortType_GetResourceProperty_impl); |
| 192 | 0 | CounterServiceDebugEnter(); |
| 193 | ||
| 194 | /* This is where it all happens. Service implementer must | |
| 195 | * implmenent this function. Asume that GetResourceProperty has | |
| 196 | * been initialized and filled with request values. | |
| 197 | * GetResourcePropertyResponse must be set by the implementer. | |
| 198 | */ | |
| 199 | ||
| 200 | 0 | result = CounterServiceErrorNotImplemented( |
| 201 | "CounterPortType_GetResourceProperty_impl"); | |
| 202 | ||
| 203 | 0 | CounterServiceDebugExit(); |
| 204 | 0 | return result; |
| 205 | } | |
| 206 | ||
| 207 | /* these functions are the service implementation and | |
| 208 | * must be implemented by the service implementer | |
| 209 | */ | |
| 210 | ||
| 211 | ||
| 212 | globus_result_t | |
| 213 | CounterPortType_QueryResourceProperties_impl( | |
| 214 | globus_service_engine_t engine, | |
| 215 | globus_soap_message_handle_t message, | |
| 216 | globus_service_descriptor_t * descriptor, | |
| 217 | wsrp_QueryResourcePropertiesType * QueryResourceProperties, | |
| 218 | wsrp_QueryResourcePropertiesResponseType * QueryResourcePropertiesResponse, | |
| 219 | const char ** fault_name, | |
| 220 | void ** fault) | |
| 221 | 0 | { |
| 222 | /* add function local variable declarations here */ | |
| 223 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 224 | ||
| 225 | /* initialize trace debugging info */ | |
| 226 | 0 | GlobusFuncName(CounterPortType_QueryResourceProperties_impl); |
| 227 | 0 | CounterServiceDebugEnter(); |
| 228 | ||
| 229 | /* This is where it all happens. Service implementer must | |
| 230 | * implmenent this function. Asume that QueryResourceProperties has | |
| 231 | * been initialized and filled with request values. | |
| 232 | * QueryResourcePropertiesResponse must be set by the implementer. | |
| 233 | */ | |
| 234 | ||
| 235 | 0 | result = CounterServiceErrorNotImplemented( |
| 236 | "CounterPortType_QueryResourceProperties_impl"); | |
| 237 | ||
| 238 | 0 | CounterServiceDebugExit(); |
| 239 | 0 | return result; |
| 240 | } | |
| 241 | ||
| 242 | ||
| 243 | ||
| 244 | /* these functions are the service implementation and | |
| 245 | * must be implemented by the service implementer | |
| 246 | */ | |
| 247 | ||
| 248 | ||
| 249 | globus_result_t | |
| 250 | CounterPortType_Destroy_impl( | |
| 251 | globus_service_engine_t engine, | |
| 252 | globus_soap_message_handle_t message, | |
| 253 | globus_service_descriptor_t * service, | |
| 254 | wsrl_DestroyType * Destroy, | |
| 255 | wsrl_DestroyResponseType * DestroyResponse, | |
| 256 | const char ** fault_name, | |
| 257 | void ** fault) | |
| 258 | 0 | { |
| 259 | /* add function local variable declarations here */ | |
| 260 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 261 | ||
| 262 | /* initialize trace debugging info */ | |
| 263 | 0 | GlobusFuncName(CounterPortType_Destroy_impl); |
| 264 | 0 | CounterServiceDebugEnter(); |
| 265 | ||
| 266 | /* This is where it all happens. Service implementer must | |
| 267 | * implmenent this function. Asume that Destroy has | |
| 268 | * been initialized and filled with request values. | |
| 269 | * DestroyResponse must be set by the implementer. | |
| 270 | */ | |
| 271 | ||
| 272 | 0 | result = CounterServiceErrorNotImplemented( |
| 273 | "CounterPortType_Destroy_impl"); | |
| 274 | ||
| 275 | 0 | CounterServiceDebugExit(); |
| 276 | 0 | return result; |
| 277 | } | |
| 278 | ||
| 279 | ||
| 280 | ||
| 281 | /* these functions are the service implementation and | |
| 282 | * must be implemented by the service implementer | |
| 283 | */ | |
| 284 | ||
| 285 | ||
| 286 | globus_result_t | |
| 287 | CounterPortType_SetTerminationTime_impl( | |
| 288 | globus_service_engine_t engine, | |
| 289 | globus_soap_message_handle_t message, | |
| 290 | globus_service_descriptor_t * service, | |
| 291 | wsrl_SetTerminationTimeType * SetTerminationTime, | |
| 292 | wsrl_SetTerminationTimeResponseType * SetTerminationTimeResponse, | |
| 293 | const char ** fault_name, | |
| 294 | void ** fault) | |
| 295 | 0 | { |
| 296 | /* add function local variable declarations here */ | |
| 297 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 298 | ||
| 299 | /* initialize trace debugging info */ | |
| 300 | 0 | GlobusFuncName(CounterPortType_SetTerminationTime_impl); |
| 301 | 0 | CounterServiceDebugEnter(); |
| 302 | ||
| 303 | /* This is where it all happens. Service implementer must | |
| 304 | * implmenent this function. Asume that SetTerminationTime has | |
| 305 | * been initialized and filled with request values. | |
| 306 | * SetTerminationTimeResponse must be set by the implementer. | |
| 307 | */ | |
| 308 | ||
| 309 | 0 | result = CounterServiceErrorNotImplemented( |
| 310 | "CounterPortType_SetTerminationTime_impl"); | |
| 311 | ||
| 312 | 0 | CounterServiceDebugExit(); |
| 313 | 0 | return result; |
| 314 | } | |
| 315 | ||
| 316 | ||
| 317 | ||
| 318 | /* these functions are the service implementation and | |
| 319 | * must be implemented by the service implementer | |
| 320 | */ | |
| 321 | ||
| 322 | ||
| 323 | globus_result_t | |
| 324 | CounterPortType_add_impl( | |
| 325 | globus_service_engine_t engine, | |
| 326 | globus_soap_message_handle_t message, | |
| 327 | globus_service_descriptor_t * service, | |
| 328 | xsd_int * add, | |
| 329 | xsd_int * addResponse, | |
| 330 | const char ** fault_name, | |
| 331 | void ** fault) | |
| 332 | 22 | { |
| 333 | /* add function local variable declarations here */ | |
| 334 | 22 | xsd_int * counter_value = NULL; |
| 335 | 22 | globus_soap_message_handle_t memory_message = NULL; |
| 336 | 22 | globus_resource_t resource = NULL; |
| 337 | 22 | globus_result_t result = GLOBUS_SUCCESS; |
| 338 | ||
| 339 | /* initialize trace debugging info */ | |
| 340 | 22 | GlobusFuncName(CounterPortType_add_impl); |
| 341 | 22 | CounterServiceDebugEnter(); |
| 342 | ||
| 343 | 22 | result = globus_wsrf_core_get_resource( |
| 344 | message, | |
| 345 | service, | |
| 346 | &resource); | |
| 347 | 22 | if(result != GLOBUS_SUCCESS) |
| 348 | { | |
| 349 | 1 | result = CounterPortType_add_chain_error( |
| 350 | result, | |
| 351 | "Failed to get resource from EPR"); | |
| 352 | 1 | goto exit; |
| 353 | } | |
| 354 | ||
| 355 | 21 | result = globus_resource_get_property(resource, |
| 356 | &CounterPortType_Value_rp_qname, (void **)&counter_value, NULL); | |
| 357 | 21 | if(result != GLOBUS_SUCCESS) |
| 358 | { | |
| 359 | 0 | result = CounterPortType_add_chain_error( |
| 360 | result, | |
| 361 | "Failed to get CounterRP resource property from resource"); | |
| 362 | 0 | goto finish_exit; |
| 363 | } | |
| 364 | ||
| 365 | 21 | *counter_value += *add; |
| 366 | 21 | *addResponse = *counter_value; |
| 367 | ||
| 368 | 21 | globus_resource_property_changed(resource, &CounterPortType_Value_rp_qname); |
| 369 | ||
| 370 | finish_exit: | |
| 371 | 21 | globus_resource_finish(resource); |
| 372 | exit: | |
| 373 | ||
| 374 | 22 | if(memory_message) |
| 375 | { | |
| 376 | 0 | globus_soap_message_handle_destroy(memory_message); |
| 377 | } | |
| 378 | ||
| 379 | 22 | CounterServiceDebugExit(); |
| 380 | 22 | return result; |
| 381 | } | |
| 382 | ||
| 383 | ||
| 384 | ||
| 385 | /* these functions are the service implementation and | |
| 386 | * must be implemented by the service implementer | |
| 387 | */ | |
| 388 | ||
| 389 | globus_result_t | |
| 390 | CounterPortType_createCounter_impl( | |
| 391 | globus_service_engine_t engine, | |
| 392 | globus_soap_message_handle_t message, | |
| 393 | globus_service_descriptor_t * service, | |
| 394 | createCounterType * createCounter, | |
| 395 | createCounterResponseType * createCounterResponse, | |
| 396 | const char ** fault_name, | |
| 397 | void ** fault) | |
| 398 | 3 | { |
| 399 | /* add function local variable declarations here */ | |
| 400 | 3 | xsd_any * counter_key; |
| 401 | 3 | char * resource_id; |
| 402 | 3 | xsd_int * counter_value; |
| 403 | 3 | globus_resource_t resource; |
| 404 | 3 | char * endpoint; |
| 405 | 3 | globus_result_t result = GLOBUS_SUCCESS; |
| 406 | ||
| 407 | /* initialize trace debugging info */ | |
| 408 | 3 | GlobusFuncName(CounterPortType_createCounter_init); |
| 409 | 3 | CounterServiceDebugEnter(); |
| 410 | ||
| 411 | 3 | resource_id = globus_common_create_string("%d", rand()); |
| 412 | ||
| 413 | 3 | memset(createCounterResponse, 0, sizeof(createCounterResponseType)); |
| 414 | ||
| 415 | 3 | wsa_ReferencePropertiesType_init( |
| 416 | &createCounterResponse->EndpointReference.ReferenceProperties); | |
| 417 | ||
| 418 | 3 | counter_key = xsd_any_array_push( |
| 419 | &createCounterResponse->EndpointReference.ReferenceProperties->any); | |
| 420 | ||
| 421 | 3 | counter_key->any_info = &xsd_string_info; |
| 422 | 3 | xsd_QName_init(&counter_key->element); |
| 423 | 3 | counter_key->element->local = globus_libc_strdup("CounterKey"); |
| 424 | 3 | counter_key->element->Namespace = globus_libc_strdup( |
| 425 | CounterService_service_qname.Namespace); | |
| 426 | 3 | xsd_string_init_cstr((xsd_string **)&counter_key->value, resource_id); |
| 427 | ||
| 428 | 3 | globus_service_engine_get_contact(engine, &endpoint); |
| 429 | ||
| 430 | 3 | createCounterResponse->EndpointReference.Address.base_value = |
| 431 | globus_common_create_string("%s/%s", endpoint, COUNTERSERVICE_BASE_PATH); | |
| 432 | ||
| 433 | 3 | free(endpoint); |
| 434 | ||
| 435 | 3 | globus_resource_create( |
| 436 | resource_id, &resource); | |
| 437 | ||
| 438 | 3 | result = CounterServiceInitResource( |
| 439 | &createCounterResponse->EndpointReference); | |
| 440 | 3 | if(result != GLOBUS_SUCCESS) |
| 441 | { | |
| 442 | 0 | result = CounterPortType_add_chain_error( |
| 443 | result, "Failed to initialize resource with service"); | |
| 444 | 0 | goto exit; |
| 445 | } | |
| 446 | ||
| 447 | 3 | xsd_int_init(&counter_value); |
| 448 | 3 | *counter_value = 0; |
| 449 | ||
| 450 | 3 | result = globus_resource_create_property( |
| 451 | resource, | |
| 452 | &CounterPortType_Value_rp_qname, | |
| 453 | &CounterPortType_Value_rp_info, counter_value); | |
| 454 | 3 | if(result != GLOBUS_SUCCESS) |
| 455 | { | |
| 456 | 0 | result = CounterPortType_add_chain_error( |
| 457 | result, "Failed to create resource property for CounterRP"); | |
| 458 | 0 | goto exit; |
| 459 | } | |
| 460 | ||
| 461 | 3 | globus_resource_finish(resource); |
| 462 | exit: | |
| 463 | ||
| 464 | 3 | CounterServiceDebugExit(); |
| 465 | 3 | return result; |