00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _WIN32
00035 #include "config.h"
00036 #else
00037 #include "winconfig.h"
00038 #endif
00039
00040 #include "include/ap_queue_template.h"
00041 #include "include/data_structures.h"
00042
00043 AP_QUEUE_STD_DEFN_TEMPLATE(connection_queue, connection)
00044
00045 AP_QUEUE_SEARCH_TEMPLATE(
00046 connection_queue,
00047 Search,
00048 connection,
00049 int,
00050 (node->connect_id == key)
00051 )
00052
00053 AP_QUEUE_REMOVE_TEMPLATE(
00054 connection_queue,
00055 Remove,
00056 connection,
00057 int,
00058 (node->connect_id == key)
00059 )
00060
00061 int
00062 connection_queue_Print(connection_queue_p queue)
00063 {
00064 int i;
00065 connection_p node;
00066 MUTEX_LOCK(queue->lock);
00067 for(i = 0; i < queue->size; i++) {
00068 node = (connection_p)ListSearch(queue->list, i);
00069 if (node != NULL) {
00070 printf("Connection id %d:\n\tremote:%s\n",
00071 node->connect_id,
00072 node->remote_hostname
00073 );
00074 }
00075 }
00076 MUTEX_UNLOCK(queue->lock);
00077 return i;
00078 }
00079
00080
00081 #include "include/interpreter_variable_data.h"
00082 AP_QUEUE_STD_DEFN_TEMPLATE(agent_variable_list, interpreter_variable_data)
00083
00084 AP_QUEUE_SEARCH_TEMPLATE(
00085 agent_variable_list,
00086 Search,
00087 interpreter_variable_data,
00088 char*,
00089 (!strcmp(node->name, key))
00090 )
00091
00092 AP_QUEUE_REMOVE_TEMPLATE(
00093 agent_variable_list,
00094 Remove,
00095 interpreter_variable_data,
00096 char*,
00097 (!strcmp(node->name, key))
00098 )
00099
00100
00101 AP_QUEUE_STD_DEFN_TEMPLATE(
00102 message_queue,
00103 message
00104 )
00105
00106 AP_QUEUE_SEARCH_TEMPLATE(
00107 message_queue,
00108 Search,
00109 message,
00110 int,
00111 (node->message_id == key)
00112 )
00113
00114 AP_QUEUE_REMOVE_TEMPLATE(
00115 message_queue,
00116 Remove,
00117 message,
00118 int,
00119 (node->message_id == key)
00120 )
00121
00122 int
00123 message_queue_Print(message_queue_p queue)
00124 {
00125 int i;
00126 message_p node;
00127 MUTEX_LOCK(queue->lock);
00128 for(i = 0; i < queue->size; i++) {
00129 node = (message_p)ListSearch(queue->list, i);
00130 if (node != NULL) {
00131 printf("Connection id %d:\n\tfrom:%s\n\tto:%s\n",
00132 node->message_id,
00133 node->from_address,
00134 node->to_address
00135 );
00136 }
00137 }
00138 MUTEX_UNLOCK(queue->lock);
00139 return i;
00140 }
00141
00142
00143
00144 #include "include/agent.h"
00145 AP_QUEUE_STD_DEFN_TEMPLATE(
00146 agent_queue,
00147 agent
00148 )
00149 AP_QUEUE_SEARCH_TEMPLATE(
00150 agent_queue,
00151 Search,
00152 agent,
00153 int,
00154 (node->id == key)
00155 )
00156 AP_QUEUE_SEARCH_TEMPLATE(
00157 agent_queue,
00158 SearchName,
00159 agent,
00160 char*,
00161 (!strcmp(node->name, key))
00162 )
00163 AP_QUEUE_REMOVE_TEMPLATE(
00164 agent_queue,
00165 Remove,
00166 agent,
00167 int,
00168 (node->id == key)
00169 )
00170 AP_QUEUE_REMOVE_TEMPLATE(
00171 agent_queue,
00172 RemoveName,
00173 agent,
00174 char*,
00175 (!strcmp(node->name, key))
00176 )
00177
00178 int
00179 agent_queue_Print(agent_queue_p queue)
00180 {
00181 int i;
00182 agent_p node;
00183 MUTEX_LOCK(queue->lock);
00184 for(i = 0; i < queue->size; i++) {
00185 node = (agent_p)ListSearch(queue->list, i);
00186 if (node != NULL) {
00187 printf("agent id %d:\n\tname:%s status:%d\n",
00188 (int)node->id,
00189 node->name, node->agent_status);
00190 }
00191 }
00192 MUTEX_UNLOCK(queue->lock);
00193 return i;
00194 }
00195
00196 int
00197 agent_queue_Flush(agent_queue_p queue)
00198 {
00199 int i;
00200 agent_p node;
00201 MUTEX_LOCK(queue->lock);
00202 for(i = 0; i < queue->size; i++) {
00203 node = (agent_p)ListSearch(queue->list, i);
00204 if (node != NULL) {
00205 printf("flushing agent id %d: name:%s status:%d\n",
00206 (int)node->id, node->name, node->agent_status);
00207 agent_queue_RemoveIndex((agent_queue_p)queue->list, i);
00208 }
00209 }
00210 MUTEX_UNLOCK(queue->lock);
00211 return i;
00212 }
00213
00214 AP_QUEUE_STD_DEFN_TEMPLATE(
00215 mail_queue,
00216 fipa_acl_message
00217 )
00218
00219 fipa_acl_message_p mail_queue_SearchReceivers( mail_queue_p mail_queue, const char* key)
00220 {
00221 listNode_t* parsenode;
00222 fipa_acl_message_t* node = NULL;
00223 fipa_acl_message_t* ret = NULL;
00224 int i;
00225
00226 MUTEX_LOCK(mail_queue->lock);
00227 if (mail_queue->list->listhead == NULL) {
00228 MUTEX_UNLOCK(mail_queue->lock);
00229 return NULL;
00230 }
00231 for(
00232 parsenode = (listNode_t*)mail_queue->list->listhead;
00233 parsenode != NULL;
00234 parsenode = (listNode_t*)parsenode->next
00235 )
00236 {
00237 node = (fipa_acl_message_t*)parsenode->node_data;
00238 for(i = 0; i < node->receiver->num; i++) {
00239 if ( !strcmp(
00240 node->receiver->fipa_agent_identifiers[i]->name,
00241 key) )
00242 {
00243 ret = node;
00244 parsenode = NULL;
00245 break;
00246 }
00247 }
00248 }
00249 return ret;
00250 }
00251
00252
00253 AP_QUEUE_STD_DEFN_TEMPLATE(
00254 mailbox_queue,
00255 agent_mailbox
00256 )
00257
00258
00259
00260 AP_QUEUE_STD_DEFN_TEMPLATE(
00261 interpreter_queue,
00262 AP_GENERIC
00263 )
00264
00265 AP_GENERIC_p interpreter_queue_CreateRetrieve( struct interpreter_queue_s *queue , ChOptions_t* interp_options) {
00266
00267
00268 struct AP_GENERIC_s *ret;
00269 ChInterp_t* interp;
00270 MUTEX_LOCK(queue->lock);
00271 if (queue->size <= 0) {
00272 interp = (ChInterp_t*)malloc(sizeof(ChInterp_t));
00273 if( Ch_Initialize(interp, interp_options) != CH_OK) {
00274
00275 MUTEX_UNLOCK(queue->lock);
00276 return NULL;
00277 }
00278
00279 agent_ChScriptInitVar(interp);
00280 ret = (struct AP_GENERIC_s*)interp;
00281 MUTEX_UNLOCK(queue->lock);
00282 return ret;
00283 }
00284 ret = (struct AP_GENERIC_s*)ListPop(queue->list);
00285 queue->size--;
00286 COND_SIGNAL(queue->cond);
00287 MUTEX_UNLOCK(queue->lock);
00288 return ret;
00289 }
00290
00291 int AP_GENERIC_Destroy(AP_GENERIC_t* blah) {
00292 return 0;
00293 }
00294
00295 AP_GENERIC_p AP_GENERIC_Copy(AP_GENERIC_p AP_GENERIC) {
00296 return NULL;
00297 }