/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 /* Message Queue */
00073 AP_QUEUE_STD_DEFN_TEMPLATE(
00074     message_queue,
00075     message
00076     )
00077 
00078 AP_QUEUE_SEARCH_TEMPLATE(
00079     message_queue,
00080     Search,
00081     message,
00082     int,
00083     (node->message_id == key)
00084     )
00085 
00086 AP_QUEUE_REMOVE_TEMPLATE(
00087     message_queue,
00088     Remove,
00089     message,
00090     int,
00091     (node->message_id == key)
00092     )
00093 
00094 int
00095 message_queue_Print(message_queue_p queue)
00096 {
00097   int i;
00098   message_p node;
00099   MUTEX_LOCK(queue->lock);
00100   for(i = 0; i < queue->size; i++) {
00101     node = (message_p)ListSearch(queue->list, i);
00102     if (node != NULL) {
00103       printf("Connection id %d:\n\tfrom:%s\n\tto:%s\n",
00104           node->message_id,
00105           node->from_address,
00106           node->to_address
00107           );
00108     }
00109   }
00110   MUTEX_UNLOCK(queue->lock);
00111   return i;
00112 }
00113 
00114 
00115 /* Agent Queue */
00116 AP_QUEUE_STD_DEFN_TEMPLATE(
00117     agent_queue,
00118     agent
00119     )
00120 AP_QUEUE_SEARCH_TEMPLATE(
00121     agent_queue,
00122     Search,
00123     agent,
00124     int,
00125     (node->id == key)
00126     )
00127 AP_QUEUE_SEARCH_TEMPLATE(
00128     agent_queue,
00129     SearchName,
00130     agent,
00131     char*,
00132     (!strcmp(node->name, key))
00133     )
00134 AP_QUEUE_REMOVE_TEMPLATE(
00135     agent_queue,
00136     Remove,
00137     agent,
00138     int,
00139     (node->id == key)
00140     )
00141 AP_QUEUE_REMOVE_TEMPLATE(
00142     agent_queue,
00143     RemoveName,
00144     agent,
00145     char*,
00146     (!strcmp(node->name, key))
00147     )
00148 
00149 int
00150 agent_queue_Print(agent_queue_p queue)
00151 {
00152   int i;
00153   agent_p node;
00154   MUTEX_LOCK(queue->lock);
00155   for(i = 0; i < queue->size; i++) {
00156     node = (agent_p)ListSearch(queue->list, i);
00157     if (node != NULL) {
00158       printf("agent id %d:\n\tname:%s\n",
00159           (int)node->id,
00160           node->name
00161           );
00162     }
00163   }
00164   MUTEX_UNLOCK(queue->lock);
00165   return i;
00166 }
00167 
00168 /* Mail Queue */
00169 AP_QUEUE_STD_DEFN_TEMPLATE(
00170     mail_queue,
00171     fipa_acl_message
00172     )
00173 
00174 fipa_acl_message_p mail_queue_SearchReceivers( mail_queue_p mail_queue, const char* key)
00175 {
00176   listNode_t* parsenode;
00177   fipa_acl_message_t* node = NULL;
00178   fipa_acl_message_t* ret = NULL;
00179   int i;
00180 
00181   MUTEX_LOCK(mail_queue->lock);
00182   if (mail_queue->list->listhead == NULL) {
00183     MUTEX_UNLOCK(mail_queue->lock);
00184     return NULL;
00185   }
00186   for(
00187       parsenode = (listNode_t*)mail_queue->list->listhead;
00188       parsenode != NULL;
00189       parsenode = (listNode_t*)parsenode->next
00190      )
00191   {
00192     node = (fipa_acl_message_t*)parsenode->node_data;
00193     for(i = 0; i < node->receiver->num; i++) {
00194       if ( !strcmp(
00195             node->receiver->fipa_agent_identifiers[i]->name,
00196             key) )
00197       {
00198         ret = node;
00199         parsenode = NULL;
00200         break;
00201       }
00202     }
00203   }
00204   return ret;
00205 }
00206 
00207 /* Mailbox Queue */
00208 AP_QUEUE_STD_DEFN_TEMPLATE(
00209     mailbox_queue,
00210     agent_mailbox
00211     )
00212 

Generated on Fri May 16 14:49:54 2008 for Mobile-C by  doxygen 1.5.4