Show SwMailbox.h syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* Copyright (c) 2001 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgement:
* This product includes software developed by Networked &
* Embedded Systems Lab at UCLA
* 4. Neither the name of the University nor that of the Laboratory
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Author: Simon Han (simonhan@ee.ucla.edu)
*/
#ifndef SW_MAILBOX_H
#define SW_MAILBOX_H
#define MAIL_ADDR_ALL 0
#ifdef SW_DEBUG
#define DEBUG(arg...) printf(arg)
#else
#define DEBUG(arg...)
#endif
typedef struct{
unsigned int node;
unsigned int instance;
unsigned char user;
unsigned char family;
unsigned char padding[2];
} __attribute__ ((packed))
SwAddress;
void printAddress(SwAddress addr);
typedef struct{
signed int mtype;
SwAddress dst;
SwAddress src;
unsigned int size;
unsigned int orig_size;
} __attribute__ ((packed))
SwMessageHdr;
typedef struct{
SwMessageHdr hdr;
unsigned char *data;
} __attribute__ ((packed))
SwMessage;
typedef struct{
SwAddress addr; // agent address
int numberMail; // number of mails in the buffer
pthread_mutex_t lock; // mutext
pthread_cond_t newmail; // conditional var for new mail
int rdIdx; // mail reader index
int wrIdx; // mail writer index
SwMessage mail[MAXNUMBERMAIL]; // mail buffer
} SwMailbox;
void printMessage(SwMessage msg);
#define SW_MSG_SIZE (sizeof(SwMessage) - sizeof(long))
int swMailInit(int id);
int swMailOpen(SwMailbox *mbox);
int swMailClose(SwMailbox *mbox);
int swMailSend(SwMessage *msg);
int swMailRecv(SwMailbox *mbox, SwMessage *msg);
inline void swMailConstructMsgHdr(SwMessageHdr *hdrptr, long type,
SwAddress *dstPtr, SwAddress *srcPtr,
u_int16_t size);
inline int swMailGetNodeId();
void swMailFreeAll(SwMailbox *mbox);
int swMailReserve(SwAddress *addr);
#endif
See more files for this project here