| 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 "globus_i_service_engine.h" | |
| 19 | #include <syslog.h> | |
| 20 | ||
| 21 | /** | |
| 22 | * Destroy a service engine | |
| 23 | * @ingroup globus_service_engine | |
| 24 | * | |
| 25 | * Destroys a stopped service engine, releasing all resources associated | |
| 26 | * with it. | |
| 27 | * | |
| 28 | * @param engine | |
| 29 | * Engine to destroy. After this call is complete, the engine reference is | |
| 30 | * invalid. | |
| 31 | * | |
| 32 | * @return void | |
| 33 | */ | |
| 34 | void | |
| 35 | globus_service_engine_destroy( | |
| 36 | globus_service_engine_t engine) | |
| 37 | 260 | { |
| 38 | int res; | |
| 39 | globus_list_t * tmp; | |
| 40 | GlobusFuncName(globus_service_engine_destroy); | |
| 41 | 260 | GlobusServiceEngineDebugEnter(); |
| 42 | ||
| 43 | 260 | if (engine == NULL) |
| 44 | { | |
| 45 | 0 | goto out; |
| 46 | } | |
| 47 | ||
| 48 | 260 | GlobusServiceEngineExtensionLock(); |
| 49 | 260 | tmp = globus_list_search( |
| 50 | globus_i_service_engine_instances, | |
| 51 | engine); | |
| 52 | ||
| 53 | 260 | if (tmp != NULL) |
| 54 | { | |
| 55 | 260 | globus_list_remove(&globus_i_service_engine_instances, tmp); |
| 56 | } | |
| 57 | else | |
| 58 | { | |
| 59 | 0 | GlobusServiceEngineExtensionUnlock(); |
| 60 | 0 | return; |
| 61 | } | |
| 62 | ||
| 63 | 260 | GlobusServiceEngineExtensionUnlock(); |
| 64 | 260 | if(engine->handlers) |
| 65 | { | |
| 66 | 260 | globus_handler_chain_destroy(engine->handlers); |
| 67 | } | |
| 68 | ||
| 69 | 260 | if(engine->contact) |
| 70 | { | |
| 71 | 260 | free(engine->contact); |
| 72 | } | |
| 73 | ||
| 74 | 260 | if(engine->server) |
| 75 | { | |
| 76 | 260 | globus_xio_server_close(engine->server); |
| 77 | } | |
| 78 | ||
| 79 | 260 | res = globus_mutex_destroy(&engine->mutex); |
| 80 | 260 | globus_assert_string((res == 0), "Failed to destroy mutex"); |
| 81 | ||
| 82 | 260 | if(engine->attrs) |
| 83 | { | |
| 84 | 260 | globus_soap_message_attr_destroy(engine->attrs); |
| 85 | } | |
| 86 | 260 | if (engine->logger) |
| 87 | { | |
| 88 | 0 | globus_logging_write( |
| 89 | engine->logger, | |
| 90 | LOG_INFO, | |
| 91 | "event=globus_service_engine.end " | |
| 92 | "engine_id=%s " | |
| 93 | "status=0\n", | |
| 94 | engine->id); | |
| 95 | } | |
| 96 | ||
| 97 | 260 | if (globus_i_service_engine_usage != NULL) |
| 98 | { | |
| 99 | 260 | size_t len = 0; |
| 100 | 260 | char * service_list_string = NULL; |
| 101 | char * uri; | |
| 102 | ||
| 103 | 260 | for (uri = globus_hashtable_first(&engine->services); |
| 104 | 779 | uri != NULL; |
| 105 | 259 | uri = globus_hashtable_next(&engine->services)) |
| 106 | { | |
| 107 | 259 | len += strlen(uri) + 10; |
| 108 | } | |
| 109 | 260 | service_list_string = malloc(len+1); |
| 110 | 260 | service_list_string[0] = 0; |
| 111 | 260 | len = 0; |
| 112 | 260 | for (uri = globus_hashtable_first(&engine->services); |
| 113 | 779 | uri != NULL; |
| 114 | 259 | uri = globus_hashtable_next(&engine->services)) |
| 115 | { | |
| 116 | 259 | len += sprintf(service_list_string + len, |
| 117 | "%s%s", | |
| 118 | len == 0 ? "" : ",", | |
| 119 | uri); | |
| 120 | } | |
| 121 | 260 | if (service_list_string[0] != 0) |
| 122 | { | |
| 123 | 253 | globus_usage_stats_send(globus_i_service_engine_usage, |
| 124 | 3, | |
| 125 | "ID", | |
| 126 | engine->id, | |
| 127 | "EVENT", | |
| 128 | "2", | |
| 129 | "SERVICES", | |
| 130 | service_list_string); | |
| 131 | } | |
| 132 | else | |
| 133 | { | |
| 134 | 7 | globus_usage_stats_send(globus_i_service_engine_usage, |
| 135 | 2, | |
| 136 | "ID", | |
| 137 | engine->id, | |
| 138 | "EVENT", | |
| 139 | "2"); | |
| 140 | } | |
| 141 | 260 | free(service_list_string); |
| 142 | } | |
| 143 | 260 | globus_hashtable_destroy_all(&engine->services, free); |
| 144 | ||
| 145 | 260 | free(engine); |
| 146 | 260 | out: |
| 147 | 260 | GlobusServiceEngineDebugExit(); |
| 148 | } |