/home/dko/projects/mobilec/trunk/src/data_structures.c

Go to the documentation of this file.
00001 /*[
00002  * Copyright (c) 2007 Integration Engineering Laboratory
00003                       University of California, Davis
00004  *
00005  * Permission to use, copy, and distribute this software and its
00006  * documentation for any purpose with or without fee is hereby granted,
00007  * provided that the above copyright notice appear in all copies and
00008  * that both that copyright notice and this permission notice appear
00009  * in supporting documentation.
00010  *
00011  * Permission to modify the software is granted, but not the right to
00012  * distribute the complete modified source code.  Modifications are to
00013  * be distributed as patches to the released version.  Permission to
00014  * distribute binaries produced by compiling modified sources is granted,
00015  * provided you
00016  *   1. distribute the corresponding source modifications from the
00017  *    released version in the form of a patch file along with the binaries,
00018  *   2. add special version identification to distinguish your version
00019  *    in addition to the base release version number,
00020  *   3. provide your name and address as the primary contact for the
00021  *    support of your modified version, and
00022  *   4. retain our contact information in regard to use of the base
00023  *    software.
00024  * Permission to distribute the released version of the source code along
00025  * with corresponding source modifications in the form of a patch file is
00026  * granted with same provisions 2 through 4 for binary distributions.
00027  *
00028  * This software is provided "as is" without express or implied warranty
00029  * to the extent permitted by applicable law.
00030 ]*/
00031 
00032 #include "include/ap_queue_template.h"
00033 #include "include/data_structures.h"
00034 /* Connection Queue */
00035 AP_QUEUE_STD_DEFN_TEMPLATE(connection_queue, connection)
00036 
00037 AP_QUEUE_SEARCH_TEMPLATE(
00038     connection_queue,
00039     Search,
00040     connection,
00041     int,
00042     (node->connect_id == key)
00043     )
00044 
00045 AP_QUEUE_REMOVE_TEMPLATE(
00046     connection_queue,
00047     Remove,
00048     connection,
00049     int,
00050     (node->connect_id == key)
00051     )
00052 
00053 int 
00054 connection_queue_Print(connection_queue_p queue)
00055 {
00056   int i;
00057   connection_p node;
00058   MUTEX_LOCK(queue->lock);
00059   for(i = 0; i < queue->size; i++) {
00060     node = (connection_p)ListSearch(queue->list, i);
00061     if (node != NULL) {
00062       printf("Connection id %d:\n\tremote:%s\n",
00063           node->connect_id,
00064           node->remote_hostname
00065           );
00066     }
00067   }
00068   MUTEX_UNLOCK(queue->lock);
00069   return i;
00070 }
00071 
00072 /* Agent variables */
00073 #include "include/interpreter_variable_data.h"
00074 AP_QUEUE_STD_DEFN_TEMPLATE(agent_variable_list, interpreter_variable_data)
00075 
00076 AP_QUEUE_SEARCH_TEMPLATE(
00077     agent_variable_list,
00078     Search,
00079     interpreter_variable_data,
00080     char*,
00081     (!strcmp(node->name, key))
00082     )
00083 
00084 AP_QUEUE_REMOVE_TEMPLATE(
00085     agent_variable_list,
00086     Remove,
00087     interpreter_variable_data,
00088     char*,
00089     (!strcmp(node->name, key))
00090     )
00091         
00092 /* Message Queue */
00093 AP_QUEUE_STD_DEFN_TEMPLATE(
00094     message_queue,
00095     message
00096     )
00097 
00098 AP_QUEUE_SEARCH_TEMPLATE(
00099     message_queue,
00100     Search,
00101     message,
00102     int,
00103     (node->message_id == key)
00104     )
00105 
00106 AP_QUEUE_REMOVE_TEMPLATE(
00107     message_queue,
00108     Remove,
00109     message,
00110     int,
00111     (node->message_id == key)
00112     )
00113 
00114 int
00115 message_queue_Print(message_queue_p queue)
00116 {
00117   int i;
00118   message_p node;
00119   MUTEX_LOCK(queue->lock);
00120   for(i = 0; i < queue->size; i++) {
00121     node = (message_p)ListSearch(queue->list, i);
00122     if (node != NULL) {
00123       printf("Connection id %d:\n\tfrom:%s\n\tto:%s\n",
00124           node->message_id,
00125           node->from_address,
00126           node->to_address
00127           );
00128     }
00129   }
00130   MUTEX_UNLOCK(queue->lock);
00131   return i;
00132 }
00133 
00134 
00135 /* Agent Queue */
00136 #include "include/agent.h"
00137 AP_QUEUE_STD_DEFN_TEMPLATE(
00138     agent_queue,
00139     agent
00140     )
00141 AP_QUEUE_SEARCH_TEMPLATE(
00142     agent_queue,
00143     Search,
00144     agent,
00145     int,
00146     (node->id == key)
00147     )
00148 AP_QUEUE_SEARCH_TEMPLATE(
00149     agent_queue,
00150     SearchName,
00151     agent,
00152     char*,
00153     (!strcmp(node->name, key))
00154     )
00155 AP_QUEUE_REMOVE_TEMPLATE(
00156     agent_queue,
00157     Remove,
00158     agent,
00159     int,
00160     (node->id == key)
00161     )
00162 AP_QUEUE_REMOVE_TEMPLATE(
00163     agent_queue,
00164     RemoveName,
00165     agent,
00166     char*,
00167     (!strcmp(node->name, key))
00168     )
00169 
00170 int
00171 agent_queue_Print(agent_queue_p queue)
00172 {
00173   int i;
00174   agent_p node;
00175   MUTEX_LOCK(queue->lock);
00176   for(i = 0; i < queue->size; i++) {
00177     node = (agent_p)ListSearch(queue->list, i);
00178     if (node != NULL) {
00179       printf("agent id %d:\n\tname:%s\n",
00180           (int)node->id,
00181           node->name
00182           );
00183     }
00184   }
00185   MUTEX_UNLOCK(queue->lock);
00186   return i;
00187 }
00188 
00189 /* Mail Queue */
00190 AP_QUEUE_STD_DEFN_TEMPLATE(
00191     mail_queue,
00192     fipa_acl_message
00193     )
00194 
00195 fipa_acl_message_p mail_queue_SearchReceivers( mail_queue_p mail_queue, const char* key)
00196 {
00197   listNode_t* parsenode;
00198   fipa_acl_message_t* node = NULL;
00199   fipa_acl_message_t* ret = NULL;
00200   int i;
00201 
00202   MUTEX_LOCK(mail_queue->lock);
00203   if (mail_queue->list->listhead == NULL) {
00204     MUTEX_UNLOCK(mail_queue->lock);
00205     return NULL;
00206   }
00207   for(
00208       parsenode = (listNode_t*)mail_queue->list->listhead;
00209       parsenode != NULL;
00210       parsenode = (listNode_t*)parsenode->next
00211      )
00212   {
00213     node = (fipa_acl_message_t*)parsenode->node_data;
00214     for(i = 0; i < node->receiver->num; i++) {
00215       if ( !strcmp(
00216             node->receiver->fipa_agent_identifiers[i]->name,
00217             key) )
00218       {
00219         ret = node;
00220         parsenode = NULL;
00221         break;
00222       }
00223     }
00224   }
00225   return ret;
00226 }
00227 
00228 /* Mailbox Queue */
00229 AP_QUEUE_STD_DEFN_TEMPLATE(
00230     mailbox_queue,
00231     agent_mailbox
00232     )
00233 

Generated on Mon Jun 23 16:01:09 2008 for Mobile-C by  doxygen 1.5.4