00001 /* SVN FILE INFO 00002 * $Revision: 316 $ : Last Committed Revision 00003 * $Date: 2009-04-29 16:40:54 -0700 (Wed, 29 Apr 2009) $ : Last Committed Date */ 00004 #ifndef _WIN32 00005 #include "config.h" 00006 #else 00007 #include "winconfig.h" 00008 #endif 00009 00010 #include "include/data_structures.h" 00011 00012 agent_mailbox_p agent_mailbox_New(void) 00013 { 00014 agent_mailbox_p mailbox; 00015 mailbox = (agent_mailbox_p)malloc(sizeof(agent_mailbox_t)); 00016 memset(mailbox, 0, sizeof(agent_mailbox_t)); 00017 mailbox->mail_queue = mail_queue_New(); 00018 return mailbox; 00019 } 00020 00021 agent_mailbox_p agent_mailbox_Copy(agent_mailbox_p src) 00022 { 00023 agent_mailbox_p tmp; 00024 tmp = agent_mailbox_New(); 00025 tmp->mail_queue = mail_queue_Copy(src->mail_queue); 00026 return tmp; 00027 } 00028 00029 int agent_mailbox_Destroy(agent_mailbox_t* mailbox) 00030 { 00031 if (mailbox == NULL) return 0; 00032 mail_queue_Destroy(mailbox->mail_queue); 00033 free(mailbox); 00034 00035 return 0; 00036 } 00037 00038 int agent_mailbox_Post(agent_mailbox_p mailbox, fipa_acl_message_t* message) 00039 { 00040 mail_queue_Add(mailbox->mail_queue, message); 00041 return 0; 00042 } 00043 00044 fipa_acl_message_t* agent_mailbox_Retrieve(agent_mailbox_p mailbox) 00045 { 00046 return mail_queue_Pop(mailbox->mail_queue); 00047 } 00048 00049 fipa_acl_message_t* agent_mailbox_WaitRetrieve(agent_mailbox_p mailbox) 00050 { 00051 MUTEX_LOCK(mailbox->mail_queue->lock); 00052 while ( mailbox->mail_queue->size == 0 ) { 00053 COND_WAIT(mailbox->mail_queue->cond, mailbox->mail_queue->lock); 00054 } 00055 MUTEX_UNLOCK(mailbox->mail_queue->lock); 00056 return agent_mailbox_Retrieve(mailbox); 00057 } 00058