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