/**---------------------------------------------------------------------------
* 版权 2004 啄木鸟基金会
* 保留一切权利。
* 
* 重新分发或者使用源代码格式和二进制格式，无论是否修改，必须在符合
* 以下许可条件的情况下进行：
* 1. 重新分发的源代码必须保留上述版权信息、本许可条件列表以及下列
*    否认声明。
* 2. 重新分发的二进制格式程序必须再次产生上述版权信息，本许可条件列
*    表以及在本分发中的文档或者其他材料中提供的否认声明。
*
* 本软件是由作者和参与者“照此”提供，并且任何显式或隐式的保证，只
* 包含在内但不被其限制，否认任何商业性和特殊目的适切性的隐式担保
* 之效力。本软件的作者或参与者不对由于本软件造成的任何直接地、
* 间接地、连带地、特殊地、惩戒性地，或者由此而产生地损害（还包括
* 以下的不被其限制的内容在内：替代品或服务地取得；使用过程、数据、
* 或由此产生的收益之损失；或商业行为的中断）发生在即使被告知可能
* 出现上述损害后，仍设法摆脱使用本软件的过程中，无论其起因和任何
* 责任地推测，其是否属于合同范畴、限定的义务、或者民事侵权行为
*（包括疏忽及其他）都否认其责任。
* 
* 
*
* Copyright (c) 2004 The Woodpecker Foundation
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
**---------------------------------------------------------------------------
*/

#ifndef _ROO_H_
#define _ROO_H_
#define ROO_REQT_POOL "/tmp/rooREQTpool"
#define ROO_RESP_POOL "/tmp/rooRESPpool"
#define ROO_SLEEP_TIME 0.0001

#define ROO_NOHANG  0  //if operate fail, return immediately
#define ROO_WAIT   -1  //if operate fail, don't return and try until succ

#define ROO_FLAG_REMOVE    1  //remove the region, when operate
#define ROO_FLAG_NOTREMOVE 0  //dont't remove the region, when operate

#define ROO_TOANYONE 0;       //anyone cant access this message

#define ROO_FUNC_PUSH  1
#define ROO_FUNC_PULL  2
#define ROO_FUNC_POPUP 3
#define ROO_FUNC_FETCH 4 

#define ROO_FUNCTYPE_WRITE 1
#define ROO_FUNCTYPE_READ  2

// user's setting
typedef struct rooProfile_t rooProfile;
struct rooProfile_t{
    unsigned long SenderID;
    int RemoveFlag;
    int WriteTimeOut;
    int ReadTimeOut;
};

/* 池管理函数 */
int rooCreatePool(char *PoolName, int MaxSize, int TimeOut);
int rooDestroyPool(char *PoolName);

char *rooGetPoolInfo(char *PoolName, char *Buffer);
char *rooGetAllPoolInfo(char *Buffer);
void rooPoolGC();

void getProfile(rooProfile *profile);
void setProfile(rooProfile *profile);

/* 访问接口函数 */
int rooPush(char *PoolName, void *Buffer, int Size, unsigned long Receiver); 
// the follow fucntion will malloc memory to Buffer, you MUST free yourself!!
int rooPull(char *PoolName, void **Buffer, unsigned long  *Sender);
int rooPopup(char *PoolName, void **Buffer, unsigned long  *Sender);
int rooFetch(char *PoolName, void **Buffer, unsigned long  *Sender);

/* helper function */
int charPush(char *PoolName, char *Buffer, int Size, unsigned long Receiver); 
// the follow fucntion will malloc memory to Buffer, you MUST free yourself!!
int charPull(char *PoolName, char **Buffer, unsigned long  *Sender);
int charPopup(char *PoolName, char **Buffer, unsigned long  *Sender);
int charFetch(char *PoolName, char **Buffer, unsigned long  *Sender);

int getTimeOut(int FunctionType);
void setTimeOut(int FunctionType, int TimeOut);
int getRemoveFlag();
void setRemoveFlag(int RemoveFlag);

#endif _ROO_H_
