1 /*
2  * Portions of this file Copyright 1999-2005 University of Chicago
3  * Portions of this file Copyright 1999-2005 The University of Southern California.
4  *
5  * This file or a portion of this file is licensed under the
6  * terms of the Globus Toolkit Public License, found at
7  * http://www.globus.org/toolkit/download/license.html.
8  * If you redistribute this file, with or without
9  * modifications, you must include this notice in the file.
10  */
11
12
13 #include "CounterService_skeleton.h"
14 #include "CounterService_internal_skeleton.h"
15
16 #include "globus_wsrf_resource.h"
17 #include "globus_wsrf_core_tools.h"
18 #include "globus_soap_message_handle.h"
19
20 extern globus_service_descriptor_t CounterService_descriptor;
21
22
23 globus_result_t
24 CounterService_init(
25     globus_service_descriptor_t *       service_desc)
26 4 {
27 4     int                                 rc;
28
29 4     GlobusFuncName(CounterService_init);
30 4     CounterServiceDebugEnter();
31
32 4     rc = globus_module_activate(GLOBUS_WSRF_RESOURCE_MODULE);
33
34 4     CounterServiceDebugExit();
35
36 4     return (rc == GLOBUS_SUCCESS) ? GLOBUS_SUCCESS : GLOBUS_FAILURE;
37 }
38
39 globus_result_t
40 CounterService_finalize(
41     globus_service_descriptor_t *       service_desc)
42 0 {
43 0     int                                 rc;
44 0     GlobusFuncName(CounterService_finalize);
45
46 0     CounterServiceDebugEnter();
47
48     /* do any service specific finalize stuff here, 
49      * opposite of CounterService_init
50      */
51
52 0     rc = globus_module_deactivate(GLOBUS_WSRF_RESOURCE_MODULE);
53
54 0     CounterServiceDebugExit();
55
56 0     return (rc == GLOBUS_SUCCESS) ? GLOBUS_SUCCESS : GLOBUS_FAILURE;
57 }
58
59 /* these functions are the service implementation and
60  * must be implemented by the service implementer
61  */
62
63 globus_result_t
64 CounterPortType_GetCurrentMessage_init(
65     globus_service_engine_t             engine,
66     globus_soap_message_handle_t        message,
67     wsnt_GetCurrentMessageType * GetCurrentMessage)
68 0 {
69     /* add function local variable declarations here */
70 0     globus_result_t                     result = GLOBUS_SUCCESS;
71
72     /* initialize trace debugging info */
73 0     GlobusFuncName(CounterPortType_GetCurrentMessage_init);
74 0     CounterServiceDebugEnter();
75
76     /* Service implementer may implmenent this function.  Since this
77      * function gets called before deserialization of the request
78      * message, the input variable GetCurrentMessage can be initialized
79      * however the implementer wants, as well as making any configuration
80      * changes to the service engine or soap message handles.
81      *
82      * If no configuration or initialization needs to be done, this
83      * call can remain empty.
84      */
85
86 0     CounterServiceDebugExit();
87 0     return GLOBUS_SUCCESS;
88 }
89
90 globus_result_t
91 CounterPortType_GetCurrentMessage_impl(
92     globus_service_engine_t             engine,
93     globus_soap_message_handle_t        message,
94     globus_service_descriptor_t *       service,
95     wsnt_GetCurrentMessageType * GetCurrentMessage,
96     wsnt_GetCurrentMessageResponseType * GetCurrentMessageResponse,
97     const char **                       fault_name,
98     void ** fault)
99 0 {
100     /* add function local variable declarations here */
101 0     globus_result_t                     result = GLOBUS_SUCCESS;
102
103     /* initialize trace debugging info */
104 0     GlobusFuncName(CounterPortType_GetCurrentMessage_impl);
105 0     CounterServiceDebugEnter();
106      
107     /* This is where it all happens.  Service implementer must 
108      * implmenent this function.  Asume that GetCurrentMessage has
109      * been initialized and filled with request values.  
110      * GetCurrentMessageResponse must be set by the implementer.
111      */
112
113 0     result = CounterServiceErrorNotImplemented(
114         "CounterPorType_GetCurrentMessage_impl");
115
116 0     CounterServiceDebugExit();
117 0     return result;     
118 }
119
120
121
122 /* these functions are the service implementation and
123  * must be implemented by the service implementer
124  */
125
126 globus_result_t
127 CounterPortType_Subscribe_init(
128     globus_service_engine_t             engine,
129     globus_soap_message_handle_t        message,
130     wsnt_SubscribeType * Subscribe)
131 1 {
132     /* add function local variable declarations here */
133 1     globus_result_t                     result = GLOBUS_SUCCESS;
134
135     /* initialize trace debugging info */
136 1     GlobusFuncName(CounterPortType_Subscribe_init);
137 1     CounterServiceDebugEnter();
138
139     /* Service implementer may implmenent this function.  Since this
140      * function gets called before deserialization of the request
141      * message, the input variable Subscribe can be initialized
142      * however the implementer wants, as well as making any configuration
143      * changes to the service engine or soap message handles.
144      *
145      * If no configuration or initialization needs to be done, this
146      * call can remain empty.
147      */
148
149 1     CounterServiceDebugExit();
150 1     return GLOBUS_SUCCESS;
151 }
152
153 globus_result_t
154 CounterPortType_Subscribe_impl(
155     globus_service_engine_t             engine,
156     globus_soap_message_handle_t        message,
157     globus_service_descriptor_t *       service,
158     wsnt_SubscribeType * Subscribe,
159     wsnt_SubscribeResponseType * SubscribeResponse,
160     const char **                       fault_name,
161     void ** fault)
162 1 {
163     /* add function local variable declarations here */
164 1     globus_result_t                     result = GLOBUS_SUCCESS;
165
166     /* initialize trace debugging info */
167 1     GlobusFuncName(CounterPortType_Subscribe_impl);
168 1     CounterServiceDebugEnter();
169      
170     /* This is where it all happens.  Service implementer must 
171      * implmenent this function.  Asume that Subscribe has
172      * been initialized and filled with request values.  
173      * SubscribeResponse must be set by the implementer.
174      */
175
176 1     result = CounterServiceErrorNotImplemented(
177         "CounterPortType_Subscribe_impl");
178
179 1     CounterServiceDebugExit();
180 1     return result;     
181 }
182
183 /* these functions are the service implementation and
184  * must be implemented by the service implementer
185  */
186
187 globus_result_t
188 CounterPortType_GetMultipleResourceProperties_init(
189     globus_service_engine_t             engine,
190     globus_soap_message_handle_t        message,
191     wsrp_GetMultipleResourcePropertiesType * GetMultipleResourceProperties)
192 0 {
193     /* add function local variable declarations here */
194 0     globus_result_t                     result = GLOBUS_SUCCESS;
195
196     /* initialize trace debugging info */
197 0     GlobusFuncName(CounterPortType_GetResourceProperties_init);
198 0     CounterServiceDebugEnter();
199
200     /* Service implementer may implmenent this function.  Since this
201      * function gets called before deserialization of the request
202      * message, the input variable GetResourceProperty can be initialized
203      * however the implementer wants, as well as making any configuration
204      * changes to the service engine or soap message handles.
205      *
206      * If no configuration or initialization needs to be done, this
207      * call can remain empty.
208      */
209
210 0     CounterServiceDebugExit();
211 0     return GLOBUS_SUCCESS;
212 }
213
214 globus_result_t
215 CounterPortType_GetMultipleResourceProperties_impl(
216     globus_service_engine_t             engine,
217     globus_soap_message_handle_t        message,
218     globus_service_descriptor_t *       service,
219     wsrp_GetMultipleResourcePropertiesType * GetResourceProperty,
220     wsrp_GetMultipleResourcePropertiesResponseType * GetMultipleResourcePropertiesResponse,
221     const char **                       fault_name,
222     void ** fault)
223 0 {
224     /* add function local variable declarations here */
225 0     globus_result_t                     result = GLOBUS_SUCCESS;
226
227     /* initialize trace debugging info */
228 0     GlobusFuncName(CounterPortType_GetMultipleResourceProperties_impl);
229 0     CounterServiceDebugEnter();
230      
231     /* This is where it all happens.  Service implementer must 
232      * implmenent this function.  Asume that GetResourceProperty has
233      * been initialized and filled with request values.  
234      * GetResourcePropertyResponse must be set by the implementer.
235      */
236
237 0     result = CounterServiceErrorNotImplemented(
238         "CounterPortType_GetMultipleResourceProperties_impl");
239
240 0     CounterServiceDebugExit();
241 0     return result;     
242 }
243
244
245
246 /* these functions are the service implementation and
247  * must be implemented by the service implementer
248  */
249
250 globus_result_t
251 CounterPortType_GetResourceProperty_init(
252     globus_service_engine_t             engine,
253     globus_soap_message_handle_t        message,
254     xsd_QName * GetResourceProperty)
255 0 {
256     /* add function local variable declarations here */
257 0     globus_result_t                     result = GLOBUS_SUCCESS;
258
259     /* initialize trace debugging info */
260 0     GlobusFuncName(CounterPortType_GetResourceProperty_init);
261 0     CounterServiceDebugEnter();
262
263     /* Service implementer may implmenent this function.  Since this
264      * function gets called before deserialization of the request
265      * message, the input variable GetResourceProperty can be initialized
266      * however the implementer wants, as well as making any configuration
267      * changes to the service engine or soap message handles.
268      *
269      * If no configuration or initialization needs to be done, this
270      * call can remain empty.
271      */
272
273 0     CounterServiceDebugExit();
274 0     return GLOBUS_SUCCESS;
275 }
276
277 globus_result_t
278 CounterPortType_GetResourceProperty_impl(
279     globus_service_engine_t             engine,
280     globus_soap_message_handle_t        message,
281     globus_service_descriptor_t *       service,
282     xsd_QName * GetResourceProperty,
283     wsrp_GetResourcePropertyResponseType * GetResourcePropertyResponse,
284     const char **                       fault_name,
285     void ** fault)
286 0 {
287     /* add function local variable declarations here */
288 0     globus_result_t                     result = GLOBUS_SUCCESS;
289
290     /* initialize trace debugging info */
291 0     GlobusFuncName(CounterPortType_GetResourceProperty_impl);
292 0     CounterServiceDebugEnter();
293      
294     /* This is where it all happens.  Service implementer must 
295      * implmenent this function.  Asume that GetResourceProperty has
296      * been initialized and filled with request values.  
297      * GetResourcePropertyResponse must be set by the implementer.
298      */
299
300 0     result = CounterServiceErrorNotImplemented(
301         "CounterPortType_GetResourceProperty_impl");
302
303 0     CounterServiceDebugExit();
304 0     return result;     
305 }
306
307 /* these functions are the service implementation and
308  * must be implemented by the service implementer
309  */
310
311 globus_result_t
312 CounterPortType_QueryResourceProperties_init(
313     globus_service_engine_t             engine,
314     globus_soap_message_handle_t        message,
315     wsrp_QueryResourcePropertiesType * QueryResourceProperties)
316 0 {
317     /* add function local variable declarations here */
318 0     globus_result_t                     result = GLOBUS_SUCCESS;
319
320     /* initialize trace debugging info */
321 0     GlobusFuncName(CounterPortType_QueryResourceProperties_init);
322 0     CounterServiceDebugEnter();
323
324     /* Service implementer may implmenent this function.  Since this
325      * function gets called before deserialization of the request
326      * message, the input variable QueryResourceProperties can be initialized
327      * however the implementer wants, as well as making any configuration
328      * changes to the service engine or soap message handles.
329      *
330      * If no configuration or initialization needs to be done, this
331      * call can remain empty.
332      */
333
334 0     CounterServiceDebugExit();
335 0     return GLOBUS_SUCCESS;
336 }
337
338 globus_result_t
339 CounterPortType_QueryResourceProperties_impl(
340     globus_service_engine_t             engine,
341     globus_soap_message_handle_t        message,
342     globus_service_descriptor_t *       descriptor,
343     wsrp_QueryResourcePropertiesType * QueryResourceProperties,
344     wsrp_QueryResourcePropertiesResponseType * QueryResourcePropertiesResponse,
345     const char **                       fault_name,
346     void ** fault)
347 0 {
348     /* add function local variable declarations here */
349 0     globus_result_t                     result = GLOBUS_SUCCESS;
350
351     /* initialize trace debugging info */
352 0     GlobusFuncName(CounterPortType_QueryResourceProperties_impl);
353 0     CounterServiceDebugEnter();
354      
355     /* This is where it all happens.  Service implementer must 
356      * implmenent this function.  Asume that QueryResourceProperties has
357      * been initialized and filled with request values.  
358      * QueryResourcePropertiesResponse must be set by the implementer.
359      */
360
361 0     result = CounterServiceErrorNotImplemented(
362         "CounterPortType_QueryResourceProperties_impl");
363
364 0     CounterServiceDebugExit();
365 0     return result;     
366 }
367
368
369
370 /* these functions are the service implementation and
371  * must be implemented by the service implementer
372  */
373
374 globus_result_t
375 CounterPortType_Destroy_init(
376     globus_service_engine_t             engine,
377     globus_soap_message_handle_t        message,
378     wsrl_DestroyType * Destroy)
379 0 {
380     /* add function local variable declarations here */
381 0     globus_result_t                     result = GLOBUS_SUCCESS;
382
383     /* initialize trace debugging info */
384 0     GlobusFuncName(CounterPortType_Destroy_init);
385 0     CounterServiceDebugEnter();
386
387     /* Service implementer may implmenent this function.  Since this
388      * function gets called before deserialization of the request
389      * message, the input variable Destroy can be initialized
390      * however the implementer wants, as well as making any configuration
391      * changes to the service engine or soap message handles.
392      *
393      * If no configuration or initialization needs to be done, this
394      * call can remain empty.
395      */
396
397 0     CounterServiceDebugExit();
398 0     return GLOBUS_SUCCESS;
399 }
400
401 globus_result_t
402 CounterPortType_Destroy_impl(
403     globus_service_engine_t             engine,
404     globus_soap_message_handle_t        message,
405     globus_service_descriptor_t *       service,
406     wsrl_DestroyType * Destroy,
407     wsrl_DestroyResponseType * DestroyResponse,
408     const char **                       fault_name,
409     void ** fault)
410 0 {
411     /* add function local variable declarations here */
412 0     globus_result_t                     result = GLOBUS_SUCCESS;
413
414     /* initialize trace debugging info */
415 0     GlobusFuncName(CounterPortType_Destroy_impl);
416 0     CounterServiceDebugEnter();
417      
418     /* This is where it all happens.  Service implementer must 
419      * implmenent this function.  Asume that Destroy has
420      * been initialized and filled with request values.  
421      * DestroyResponse must be set by the implementer.
422      */
423
424 0     result = CounterServiceErrorNotImplemented(
425         "CounterPortType_Destroy_impl");
426
427 0     CounterServiceDebugExit();
428 0     return result;     
429 }
430
431
432
433 /* these functions are the service implementation and
434  * must be implemented by the service implementer
435  */
436
437 globus_result_t
438 CounterPortType_SetTerminationTime_init(
439     globus_service_engine_t             engine,
440     globus_soap_message_handle_t        message,
441     wsrl_SetTerminationTimeType * SetTerminationTime)
442 0 {
443     /* add function local variable declarations here */
444 0     globus_result_t                     result = GLOBUS_SUCCESS;
445
446     /* initialize trace debugging info */
447 0     GlobusFuncName(CounterPortType_SetTerminationTime_init);
448 0     CounterServiceDebugEnter();
449
450     /* Service implementer may implmenent this function.  Since this
451      * function gets called before deserialization of the request
452      * message, the input variable SetTerminationTime can be initialized
453      * however the implementer wants, as well as making any configuration
454      * changes to the service engine or soap message handles.
455      *
456      * If no configuration or initialization needs to be done, this
457      * call can remain empty.
458      */
459
460 0     CounterServiceDebugExit();
461 0     return GLOBUS_SUCCESS;
462 }
463
464 globus_result_t
465 CounterPortType_SetTerminationTime_impl(
466     globus_service_engine_t             engine,
467     globus_soap_message_handle_t        message,
468     globus_service_descriptor_t *       service,
469     wsrl_SetTerminationTimeType * SetTerminationTime,
470     wsrl_SetTerminationTimeResponseType * SetTerminationTimeResponse,
471     const char **                       fault_name,
472     void ** fault)
473 0 {
474     /* add function local variable declarations here */
475 0     globus_result_t                     result = GLOBUS_SUCCESS;
476
477     /* initialize trace debugging info */
478 0     GlobusFuncName(CounterPortType_SetTerminationTime_impl);
479 0     CounterServiceDebugEnter();
480      
481     /* This is where it all happens.  Service implementer must 
482      * implmenent this function.  Asume that SetTerminationTime has
483      * been initialized and filled with request values.  
484      * SetTerminationTimeResponse must be set by the implementer.
485      */
486
487 0     result = CounterServiceErrorNotImplemented(
488         "CounterPortType_SetTerminationTime_impl");
489
490 0     CounterServiceDebugExit();
491 0     return result;     
492 }
493
494
495
496 /* these functions are the service implementation and
497  * must be implemented by the service implementer
498  */
499
500 globus_result_t
501 CounterPortType_add_init(
502     globus_service_engine_t             engine,
503     globus_soap_message_handle_t        message,
504     xsd_int * add)
505 13 {
506     /* add function local variable declarations here */
507 13     globus_result_t                     result = GLOBUS_SUCCESS;
508
509     /* initialize trace debugging info */
510 13     GlobusFuncName(CounterPortType_add_init);
511 13     CounterServiceDebugEnter();
512
513     /* Service implementer may implmenent this function.  Since this
514      * function gets called before deserialization of the request
515      * message, the input variable add can be initialized
516      * however the implementer wants, as well as making any configuration
517      * changes to the service engine or soap message handles.
518      *
519      * If no configuration or initialization needs to be done, this
520      * call can remain empty.
521      */
522
523 13     CounterServiceDebugExit();
524 13     return GLOBUS_SUCCESS;
525 }
526
527 globus_result_t
528 CounterPortType_add_impl(
529     globus_service_engine_t             engine,
530     globus_soap_message_handle_t        message,
531     globus_service_descriptor_t *       service,
532     xsd_int * add,
533     xsd_int * addResponse,
534     const char **                       fault_name,
535     void ** fault)
536 13 {
537     /* add function local variable declarations here */
538 13     xsd_int *                           counter_value = NULL;
539 13     globus_soap_message_handle_t        memory_message = NULL;
540 13     globus_resource_t                   resource = NULL;
541 13     globus_result_t                     result = GLOBUS_SUCCESS;
542
543     /* initialize trace debugging info */
544 13     GlobusFuncName(CounterPortType_add_init);
545 13     CounterServiceDebugEnter();
546
547 13     result = globus_wsrf_core_get_resource(
548         message,
549         service,
550         &resource);
551 13     if(result != GLOBUS_SUCCESS)
552     {
553 1         result = CounterPortType_add_chain_error(
554             result,
555             "Failed to get resource from EPR");
556 1         goto exit;
557     }
558
559 12     result = globus_resource_get_property(resource,
560         &CounterPortType_Value_rp_qname, (void **)&counter_value, NULL);
561 12     if(result != GLOBUS_SUCCESS)
562     {
563 0         result = CounterPortType_add_chain_error(
564             result, 
565             "Failed to get CounterRP resource property from resource");
566 0         goto finish_exit;
567     }
568
569 12     *counter_value += *add;
570 12     *addResponse = *counter_value;
571
572 finish_exit:
573 12     globus_resource_finish(resource);
574  exit:
575
576 13     if(memory_message)
577     {
578 0         globus_soap_message_handle_destroy(memory_message);
579     }
580     
581 13     CounterServiceDebugExit();
582 13     return result;     
583 }
584
585
586
587 /* these functions are the service implementation and
588  * must be implemented by the service implementer
589  */
590
591 globus_result_t
592 CounterPortType_createCounter_init(
593     globus_service_engine_t             engine,
594     globus_soap_message_handle_t        message,
595     createCounterType * createCounter)
596 4 {
597     /* add function local variable declarations here */
598 4     globus_result_t                     result = GLOBUS_SUCCESS;
599
600     /* initialize trace debugging info */
601 4     GlobusFuncName(CounterPortType_createCounter_init);
602 4     CounterServiceDebugEnter();
603
604     /* Service implementer may implmenent this function.  Since this
605      * function gets called before deserialization of the request
606      * message, the input variable createCounter can be initialized
607      * however the implementer wants, as well as making any configuration
608      * changes to the service engine or soap message handles.
609      *
610      * If no configuration or initialization needs to be done, this
611      * call can remain empty.
612      */
613
614 4     CounterServiceDebugExit();
615 4     return GLOBUS_SUCCESS;
616 }
617
618 globus_result_t
619 CounterPortType_createCounter_impl(
620     globus_service_engine_t             engine,
621     globus_soap_message_handle_t        message,
622     globus_service_descriptor_t *       service,
623     createCounterType * createCounter,
624     createCounterResponseType * createCounterResponse,
625     const char **                       fault_name,
626     void ** fault)
627 4 {
628     /* add function local variable declarations here */
629 4     xsd_any *                           counter_key;
630 4     char *                              resource_id;
631 4     xsd_int *                           counter_value;
632 4     globus_resource_t                   resource;
633 4     char *                              endpoint;
634 4     globus_result_t                     result = GLOBUS_SUCCESS;
635
636     /* initialize trace debugging info */
637 4     GlobusFuncName(CounterPortType_createCounter_init);
638 4     CounterServiceDebugEnter();
639      
640 4     resource_id = globus_common_create_string("%d", random());
641
642 4     globus_resource_create(
643         resource_id, &resource);
644     
645 4     result = CounterServiceInitResource(resource_id);
646 4     if(result != GLOBUS_SUCCESS)
647     {
648 0         result = CounterPortType_add_chain_error(
649             result, "Failed to initialize resource with service");
650 0         goto exit;
651     }
652
653 4     memset(createCounterResponse, 0, sizeof(createCounterResponseType));
654
655 4     wsa_ReferencePropertiesType_init(
656         &createCounterResponse->EndpointReference.ReferenceProperties);
657
658 4     counter_key = xsd_any_array_push(
659         &createCounterResponse->EndpointReference.ReferenceProperties->any);
660
661 4     counter_key->any_info = &xsd_string_info;
662 4     xsd_QName_init(&counter_key->element);
663 4     counter_key->element->local = globus_libc_strdup("CounterKey");
664 4     counter_key->element->Namespace = globus_libc_strdup(
665         CounterService_service_qname.Namespace);
666 4     xsd_string_init_cstr((xsd_string **)&counter_key->value, resource_id);
667
668 4     globus_service_engine_get_contact(engine, &endpoint);
669
670 4     createCounterResponse->EndpointReference.Address.base_value =
671     globus_common_create_string("%s/%s", endpoint, COUNTERSERVICE_BASE_PATH);
672
673 4     free(endpoint);
674
675 4     xsd_int_init(&counter_value);
676 4     *counter_value = 0;
677
678 4     result = globus_resource_create_property(
679         resource, 
680         &CounterPortType_Value_rp_qname, 
681         &CounterPortType_Value_rp_info, counter_value);
682 4     if(result != GLOBUS_SUCCESS)
683     {
684 0         result = CounterPortType_add_chain_error(
685             result, "Failed to create resource property for CounterRP");
686         goto exit;
687     }
688
689  exit:
690
691 4     CounterServiceDebugExit();
692 4     return result;