00001 #include "include/data_structures.h" 00002 00003 agent_mailbox_p agent_mailbox_New(void) 00004 { 00005 agent_mailbox_p mailbox; 00006 mailbox = (agent_mailbox_p)malloc(sizeof(agent_mailbox_t)); 00007 memset(mailbox, 0, sizeof(agent_mailbox_t)); 00008 mailbox->mail_queue = mail_queue_New(); 00009 return mailbox; 00010 } 00011 00012 int agent_mailbox_Destroy(agent_mailbox_t* mailbox) 00013 { 00014 if (mailbox == NULL) return 0; 00015 mail_queue_Destroy(mailbox->mail_queue); 00016 free(mailbox); 00017 00018 return 0; 00019 } 00020 00021 int agent_mailbox_Post(agent_mailbox_p mailbox, fipa_acl_message_t* message) 00022 { 00023 mail_queue_Add(mailbox->mail_queue, message); 00024 return 0; 00025 } 00026 00027 fipa_acl_message_t* agent_mailbox_Retrieve(agent_mailbox_p mailbox) 00028 { 00029 return mail_queue_Pop(mailbox->mail_queue); 00030 } 00031 00032 fipa_acl_message_t* agent_mailbox_WaitRetrieve(agent_mailbox_p mailbox) 00033 { 00034 MUTEX_LOCK(mailbox->mail_queue->lock); 00035 while ( mailbox->mail_queue->size == 0 ) { 00036 COND_WAIT(mailbox->mail_queue->cond, mailbox->mail_queue->lock); 00037 } 00038 MUTEX_UNLOCK(mailbox->mail_queue->lock); 00039 return agent_mailbox_Retrieve(mailbox); 00040 } 00041