| 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 "WidgetNotificationService_skeleton.h" | |
| 19 | #include "WidgetNotificationService_internal_skeleton.h" | |
| 20 | ||
| 21 | #include "globus_wsrf_resource.h" | |
| 22 | #include "globus_notification_producer.h" | |
| 23 | ||
| 24 | #define WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID "WidgetNotificationService" | |
| 25 | ||
| 26 | static wsa_EndpointReferenceType globus_l_widget_notification_epr; | |
| 27 | static wsnt_TopicExpressionType globus_l_widget_notification_topic; | |
| 28 | static xsd_QName globus_l_widget_notification_element = | |
| 29 | { | |
| 30 | "http://widgets.com", | |
| 31 | "TestNotification" | |
| 32 | }; | |
| 33 | ||
| 34 | static char globus_l_widget_notification_contents[] = | |
| 35 | "<widget:TestNotification xmlns:widget=\"http://widgets.com\"/>"; | |
| 36 | ||
| 37 | static globus_xml_buffer globus_l_widget_notification_buffer = | |
| 38 | { | |
| 39 | globus_l_widget_notification_contents, | |
| 40 | sizeof(globus_l_widget_notification_contents)-1 | |
| 41 | }; | |
| 42 | ||
| 43 | static xsd_any globus_l_widget_notification_message = | |
| 44 | { | |
| 45 | NULL, | |
| 46 | &globus_xml_buffer_info, | |
| 47 | NULL, | |
| 48 | &globus_l_widget_notification_buffer, | |
| 49 | { NULL, 0, NULL } | |
| 50 | }; | |
| 51 | ||
| 52 | static | |
| 53 | globus_result_t | |
| 54 | globus_l_widget_notification_resource_id_get( | |
| 55 | xsd_any_array * reference_parameters, | |
| 56 | char ** id) | |
| 57 | 0 | { |
| 58 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 59 | ||
| 60 | 0 | *id = globus_libc_strdup(WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID); |
| 61 | ||
| 62 | 0 | if (*id == NULL) |
| 63 | { | |
| 64 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 65 | } | |
| 66 | ||
| 67 | 0 | return result; |
| 68 | } | |
| 69 | /* globus_l_widget_notification_resource_id_get() */ | |
| 70 | ||
| 71 | static | |
| 72 | globus_result_t | |
| 73 | globus_l_widget_notification_resource_init(void) | |
| 74 | 0 | { |
| 75 | globus_result_t result; | |
| 76 | globus_resource_t resource; | |
| 77 | xsd_QName expression; | |
| 78 | xsd_anyURI * contacts; | |
| 79 | globus_size_t contacts_size; | |
| 80 | int i; | |
| 81 | ||
| 82 | 0 | result = globus_service_get_engine_contacts( |
| 83 | &contacts, | |
| 84 | &contacts_size); | |
| 85 | 0 | if (result != GLOBUS_SUCCESS) |
| 86 | { | |
| 87 | 0 | goto out; |
| 88 | } | |
| 89 | ||
| 90 | 0 | if (contacts == NULL || contacts_size < 1 || contacts[0] == NULL ) |
| 91 | { | |
| 92 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 93 | ||
| 94 | 0 | goto out; |
| 95 | } | |
| 96 | ||
| 97 | /* Create static resource for this service, so that the wsnt provider | |
| 98 | * can operate on it. The resource will have the ReferenceParameter matching | |
| 99 | * the service name. | |
| 100 | */ | |
| 101 | 0 | result = globus_resource_create( |
| 102 | WIDGETNOTIFICATIONSERVICE_BASE_PATH, | |
| 103 | &resource); | |
| 104 | 0 | if (result != GLOBUS_SUCCESS) |
| 105 | { | |
| 106 | 0 | goto destroy_contacts_out; |
| 107 | } | |
| 108 | ||
| 109 | 0 | result = wsa_EndpointReferenceType_init_contents( |
| 110 | &globus_l_widget_notification_epr); | |
| 111 | 0 | if (result != GLOBUS_SUCCESS) |
| 112 | { | |
| 113 | 0 | goto destroy_resource_out; |
| 114 | } | |
| 115 | ||
| 116 | 0 | globus_l_widget_notification_epr.Address.base_value = |
| 117 | globus_common_create_string("%s/%s", contacts[0], | |
| 118 | WIDGETNOTIFICATIONSERVICE_BASE_PATH); | |
| 119 | ||
| 120 | 0 | if (globus_l_widget_notification_epr.Address.base_value == NULL) |
| 121 | { | |
| 122 | 0 | result = GlobusSoapMessageErrorOutOfMemory; |
| 123 | ||
| 124 | 0 | goto destroy_epr_contents_out; |
| 125 | } | |
| 126 | ||
| 127 | /* Call providers to initialize resource state */ | |
| 128 | ||
| 129 | 0 | result = globus_notification_producer_create( |
| 130 | WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID, | |
| 131 | NULL, | |
| 132 | NULL); | |
| 133 | 0 | if (result != GLOBUS_SUCCESS) |
| 134 | { | |
| 135 | 0 | goto destroy_epr_contents_out; |
| 136 | } | |
| 137 | ||
| 138 | /* | |
| 139 | result = WidgetNotificationServiceInitResource(&globus_l_widget_notification_epr); | |
| 140 | if (result != GLOBUS_SUCCESS) | |
| 141 | { | |
| 142 | goto destroy_producer; | |
| 143 | } | |
| 144 | */ | |
| 145 | ||
| 146 | /* Create a simple topic "widget:TestTopic" for use in the test cases */ | |
| 147 | 0 | expression.Namespace = "http://widgets.com"; |
| 148 | 0 | expression.local = "TestTopic"; |
| 149 | 0 | result = wsnt_TopicExpressionType_init_contents(&globus_l_widget_notification_topic); |
| 150 | 0 | if (result != GLOBUS_SUCCESS) |
| 151 | { | |
| 152 | 0 | goto destroy_producer; |
| 153 | } | |
| 154 | ||
| 155 | 0 | result = globus_notification_producer_set_simple_topic_expression_contents( |
| 156 | &globus_l_widget_notification_topic, | |
| 157 | &expression); | |
| 158 | 0 | if (result != GLOBUS_SUCCESS) |
| 159 | { | |
| 160 | 0 | goto destroy_topic_out; |
| 161 | } | |
| 162 | ||
| 163 | 0 | result = globus_notification_producer_topic_create( |
| 164 | WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID, | |
| 165 | &globus_l_widget_notification_topic); | |
| 166 | 0 | if (result != GLOBUS_SUCCESS) |
| 167 | { | |
| 168 | 0 | goto destroy_topic_out; |
| 169 | } | |
| 170 | 0 | result = globus_resource_finish(resource); |
| 171 | ||
| 172 | 0 | if (result != GLOBUS_SUCCESS) |
| 173 | { | |
| 174 | 0 | destroy_topic_out: |
| 175 | 0 | wsnt_TopicExpressionType_destroy_contents(&globus_l_widget_notification_topic); |
| 176 | 0 | destroy_producer: |
| 177 | 0 | globus_notification_producer_destroy(WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID); |
| 178 | 0 | destroy_epr_contents_out: |
| 179 | 0 | wsa_EndpointReferenceType_destroy_contents(&globus_l_widget_notification_epr); |
| 180 | 0 | destroy_resource_out: |
| 181 | 0 | globus_resource_destroy(resource); |
| 182 | } | |
| 183 | 0 | destroy_contacts_out: |
| 184 | 0 | for (i = 0; i < contacts_size; i++) |
| 185 | { | |
| 186 | 0 | free(contacts[i]); |
| 187 | } | |
| 188 | 0 | free(contacts); |
| 189 | 0 | out: |
| 190 | 0 | return result; |
| 191 | } | |
| 192 | /* globus_l_widget_notification_resource_init() */ | |
| 193 | ||
| 194 | globus_result_t | |
| 195 | WidgetNotificationService_init( | |
| 196 | globus_service_descriptor_t * service_desc) | |
| 197 | 0 | { |
| 198 | globus_result_t result; | |
| 199 | ||
| 200 | GlobusFuncName(WidgetNotificationService_init); | |
| 201 | 0 | WidgetNotificationServiceDebugEnter(); |
| 202 | ||
| 203 | /* Set custom get resource function that returns the static resource key */ | |
| 204 | 0 | WidgetNotificationService_descriptor.get_resource_id = |
| 205 | globus_l_widget_notification_resource_id_get; | |
| 206 | ||
| 207 | /* Activate modules */ | |
| 208 | 0 | result = globus_module_activate(GLOBUS_NOTIFICATION_PRODUCER_MODULE); |
| 209 | 0 | if (result != GLOBUS_SUCCESS) |
| 210 | { | |
| 211 | 0 | goto out; |
| 212 | } | |
| 213 | 0 | result = globus_module_activate(GLOBUS_WSRF_RESOURCE_MODULE); |
| 214 | 0 | if (result != GLOBUS_SUCCESS) |
| 215 | { | |
| 216 | 0 | goto deactivate_out; |
| 217 | } | |
| 218 | 0 | result = globus_l_widget_notification_resource_init(); |
| 219 | 0 | if (result != GLOBUS_SUCCESS) |
| 220 | { | |
| 221 | 0 | globus_module_deactivate(GLOBUS_WSRF_RESOURCE_MODULE); |
| 222 | 0 | deactivate_out: |
| 223 | 0 | globus_module_deactivate(GLOBUS_NOTIFICATION_PRODUCER_MODULE); |
| 224 | } | |
| 225 | 0 | out: |
| 226 | 0 | WidgetNotificationServiceDebugExit(); |
| 227 | 0 | return result; |
| 228 | } | |
| 229 | ||
| 230 | globus_result_t | |
| 231 | WidgetNotificationService_finalize( | |
| 232 | globus_service_descriptor_t * service_desc) | |
| 233 | 0 | { |
| 234 | globus_result_t result; | |
| 235 | globus_resource_t resource; | |
| 236 | ||
| 237 | GlobusFuncName(WidgetNotificationService_finalize); | |
| 238 | 0 | WidgetNotificationServiceDebugEnter(); |
| 239 | ||
| 240 | 0 | result = globus_resource_find( |
| 241 | WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID, | |
| 242 | &resource); | |
| 243 | 0 | if (result != GLOBUS_SUCCESS) |
| 244 | { | |
| 245 | 0 | goto deactivate_out; |
| 246 | } | |
| 247 | ||
| 248 | 0 | globus_resource_destroy(resource); |
| 249 | 0 | wsnt_TopicExpressionType_destroy_contents(&globus_l_widget_notification_topic); |
| 250 | ||
| 251 | 0 | deactivate_out: |
| 252 | 0 | globus_module_deactivate(GLOBUS_WSRF_RESOURCE_MODULE); |
| 253 | 0 | globus_module_deactivate(GLOBUS_NOTIFICATION_PRODUCER_MODULE); |
| 254 | ||
| 255 | 0 | WidgetNotificationServiceDebugExit(); |
| 256 | 0 | return result; |
| 257 | } | |
| 258 | ||
| 259 | globus_result_t | |
| 260 | WidgetNotificationPortType_GetCurrentMessage_impl( | |
| 261 | globus_service_engine_t engine, | |
| 262 | globus_soap_message_handle_t message, | |
| 263 | globus_service_descriptor_t * descriptor, | |
| 264 | wsnt_GetCurrentMessageType * GetCurrentMessage, | |
| 265 | wsnt_GetCurrentMessageResponseType * GetCurrentMessageResponse, | |
| 266 | xsd_any * fault) | |
| 267 | 0 | { |
| 268 | /* add function local variable declarations here */ | |
| 269 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 270 | ||
| 271 | /* initialize trace debugging info */ | |
| 272 | GlobusFuncName(WidgetNotificationPortType_GetCurrentMessage_impl); | |
| 273 | 0 | WidgetNotificationServiceDebugEnter(); |
| 274 | ||
| 275 | /* This is where it all happens. Service implementer must | |
| 276 | * implmenent this function. Asume that GetCurrentMessage has | |
| 277 | * been initialized and filled with request values. | |
| 278 | * GetCurrentMessageResponse must be set by the implementer. | |
| 279 | */ | |
| 280 | ||
| 281 | /* do not use GLOBUS_FAILURE, you the error object construction api */ | |
| 282 | 0 | result = WidgetNotificationServiceErrorNotImplemented("WidgetNotificationPortType_GetCurrentMessage"); |
| 283 | ||
| 284 | 0 | WidgetNotificationServiceDebugExit(); |
| 285 | 0 | return result; |
| 286 | } | |
| 287 | ||
| 288 | ||
| 289 | ||
| 290 | globus_result_t | |
| 291 | WidgetNotificationPortType_Subscribe_impl( | |
| 292 | globus_service_engine_t engine, | |
| 293 | globus_soap_message_handle_t message, | |
| 294 | globus_service_descriptor_t * descriptor, | |
| 295 | wsnt_SubscribeType * Subscribe, | |
| 296 | wsnt_SubscribeResponseType * SubscribeResponse, | |
| 297 | xsd_any * fault) | |
| 298 | 0 | { |
| 299 | /* add function local variable declarations here */ | |
| 300 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 301 | ||
| 302 | /* initialize trace debugging info */ | |
| 303 | GlobusFuncName(WidgetNotificationPortType_Subscribe_impl); | |
| 304 | 0 | WidgetNotificationServiceDebugEnter(); |
| 305 | ||
| 306 | /* This is where it all happens. Service implementer must | |
| 307 | * implmenent this function. Asume that Subscribe has | |
| 308 | * been initialized and filled with request values. | |
| 309 | * SubscribeResponse must be set by the implementer. | |
| 310 | */ | |
| 311 | ||
| 312 | /* do not use GLOBUS_FAILURE, you the error object construction api */ | |
| 313 | 0 | result = WidgetNotificationServiceErrorNotImplemented("WidgetNotificationPortType_Subscribe"); |
| 314 | ||
| 315 | 0 | WidgetNotificationServiceDebugExit(); |
| 316 | 0 | return result; |
| 317 | } | |
| 318 | ||
| 319 | ||
| 320 | ||
| 321 | globus_result_t | |
| 322 | WidgetNotificationPortType_generateNotification_impl( | |
| 323 | globus_service_engine_t engine, | |
| 324 | globus_soap_message_handle_t message, | |
| 325 | globus_service_descriptor_t * descriptor, | |
| 326 | widget_generateNotificationType * generateNotification, | |
| 327 | widget_generateNotificationResponseType * generateNotificationResponse, | |
| 328 | xsd_any * fault) | |
| 329 | 0 | { |
| 330 | /* add function local variable declarations here */ | |
| 331 | 0 | globus_result_t result = GLOBUS_SUCCESS; |
| 332 | globus_resource_t resource; | |
| 333 | ||
| 334 | /* initialize trace debugging info */ | |
| 335 | GlobusFuncName(WidgetNotificationPortType_generateNotification_impl); | |
| 336 | 0 | WidgetNotificationServiceDebugEnter(); |
| 337 | ||
| 338 | 0 | result = globus_notification_producer_topic_changed( |
| 339 | WIDGET_NOTIFICATION_SERVICE_RESOURCE_ID, | |
| 340 | &globus_l_widget_notification_topic, | |
| 341 | &globus_l_widget_notification_message, | |
| 342 | NULL, | |
| 343 | NULL); | |
| 344 | ||
| 345 | 0 | out: |
| 346 | 0 | WidgetNotificationServiceDebugExit(); |
| 347 | 0 | return result; |