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 agent_mailbox_p agent_mailbox_Copy(agent_mailbox_p src) 00013 { 00014 agent_mailbox_p tmp; 00015 tmp = agent_mailbox_New(); 00016 tmp->mail_queue = mail_queue_Copy(src->mail_queue); 00017 return tmp; 00018 } 00019 00020 int agent_mailbox_Destroy(agent_mailbox_t* mailbox) 00021 { 00022 if (mailbox == NULL) return 0; 00023 mail_queue_Destroy(mailbox->mail_queue); 00024 free(mailbox); 00025 00026 return 0; 00027 } 00028 00029 int agent_mailbox_Post(agent_mailbox_p mailbox, fipa_acl_message_t* message) 00030 { 00031 mail_queue_Add(mailbox->mail_queue, message); 00032 return 0; 00033 } 00034 00035 fipa_acl_message_t* agent_mailbox_Retrieve(agent_mailbox_p mailbox) 00036 { 00037 return mail_queue_Pop(mailbox->mail_queue); 00038 } 00039 00040 fipa_acl_message_t* agent_mailbox_WaitRetrieve(agent_mailbox_p mailbox) 00041 { 00042 MUTEX_LOCK(mailbox->mail_queue->lock); 00043 while ( mailbox->mail_queue->size == 0 ) { 00044 COND_WAIT(mailbox->mail_queue->cond, mailbox->mail_queue->lock); 00045 } 00046 MUTEX_UNLOCK(mailbox->mail_queue->lock); 00047 return agent_mailbox_Retrieve(mailbox); 00048 } 00049