码迷,mamicode.com
首页 > 其他好文 > 详细

fossilizid简介

时间:2015-01-10 01:00:04      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:

前前后后大概维护了这些零碎的lib4年左右的时间,现在终于给这些东西加上了完整的测试用例和文档,

文档地址如下:

https://github.com/NetEase/fossilizid/tree/master/doc

代码地址如下:

https://github.com/NetEase/fossilizid

container: lock-free structure

fossilizid::container::msque

基于单链表的无锁队列

相关论文http://www.research.ibm.com/people/m/michael/podc-1996.pdf

http://web.cecs.pdx.edu/~walpole/class/cs510/papers/11.pdf

optimisticque

基于双链表的对锁队列

相关论文https://www.offblast.org/stuff/books/FIFO_Queues.pdf

ringque

基于定长数组实现的环形队列

swapque

基于读写锁,队列本身包含2个子队列,一个用于push,一个用于pop

队列采用了统一的接口设计

bool empty()

判断队列是否为空,空返回true否之返回false

std::size_tmsque::size()

获取队列长度,返回当前队列元素数目

voidmsque::clear()

清空队列

voidmsque::push(constT & data)

将元素插入队列

boolmsque::pop(T & data)

将元素弹出队列


small_hash_map

基于读写锁的hash_map,对bucket进行加锁

Interface

void for_each(boost::function<void(V var) > handle )

遍历hash_map

bool set(Kkey, Vvalue)

设置对应keyvalue

void insert(Kkey, Vvalue)

插入(keyvalue

bool search(Kkey, V &value)

查找指定key

bool erase(Kkey)

删除指定key

unsignedint size()

获取hash_map的元素数目

 

例子:fossilizid/test/test_container


pool: mempool&&objpool

fossilizid::pool::mempool

内存池,按分配的内存大小做了简单的分支管理,小于64K的内存采用链表管理,在新的内存块上保存上级节点的指针地址,大于64K的内存采用红黑树保存,直接采用了std::map

Interface

staticvoid * allocator(int len)

分配内存

staticvoid deallocator(void * buff, int len)

回收内存


fossilizid::pool::factory

对象池,采用可变长模板参数适配不同参数的构造函数

Interface

template<classT, typename ...Tlist>

staticT * create(intcount, Tlist&& ... var)

创建count个数的对象

template<classT, typename ...Tlist>

staticT * create(Tlist&& ... var)

创建一个对象

template<classT>

staticvoid release(T * p, intcount)

释放count个对象

 

例子:fossilizid/ test/test_pool


remoteq: network library

fossilizid::remoteq

基于模板适配网络协议

Interface

ACCEPTOR acceptor(QUEUE que, ENDPOINT ep)

创建接收器

CHANNEL accept(ACCEPTOR ap)

接收接入的CHANNEL

CHANNEL connect(ENDPOINT ep, QUEUE que = 0)

接入远端

void close(HANDLE _handle)

释放句柄

ENDPOINT endpoint(char * ip, short port)

创建地址

QUEUE queue()

创建事件队列

EVENT queue(QUEUE que)

获取事件

 

例子:fossilizid/test/test_remote_queue


reliablyt: udp reliably transmission

reliablyt

基于停等协议的udp可靠性传输

Interface

classUDPSession{

public:

boost::signals2::signal<void(char *, int) > sigRecv;

boost::signals2::signal<void() > sigDisConnect;

void disconnect();

void reliable_send(char * buf, int len);

void unreliable_send(char * buf, int len);

}

classUDPService : publicUDPBase{

public:

boost::signals2::signal<void(boost::shared_ptr<UDPConnect>) > sigConnect;

}


例子:fossilizid/test/test_udp


reduce: service

fossilizid::reduce

基于remoteqcontextservice,支持阻塞式rpc

Interface

classacceptservice;

监听service

classconnectservice;

接受service

classlocale_obj;

本地obj

classremote_obj;

远程obj


例子:fossilizid/test/ test_service


vchat: voice chat framework

vchat

基于portaudiospeex的多人语音聊天框架

Interface

classpaInit{

public:

paInit();

~paInit();

};

初始化 portaudio

classdevices{

public:

static std::vector<constPaDeviceInfo*> getInputDevices();

static std::vector<constPaDeviceInfo*> getOutputDevices();

};

获取设备列表

classencode{

public:

int encoded(char * inbuf, int framelen, char * outbuf, int outbuflen);

int decoded(char * inbuf, int framelen, char * outbuf, int outbuflen);

int getframesize();

};

编解码器

classsound{

public:

void start();

void stop();

boost::signals2::signal<void(char *, int)> sigCapture;

bool setOutputDevice(PaDeviceIndex index);

bool setInputDevice(PaDeviceIndex index);

void setsoundsize();

void setechostate(bool on);

};

采集接口

boost::signals2::signal<void(char *, int)> sigCapture

采集音频回调

structclient{

bool read_buff(char * & outputbuff, short & channelcount, int &len);

void write_buff(char * buff, intbuflen, shortchannelcount);

};

接入聊天的用户,用于缓存该用户的语音数据

client * create_client(int index = 0)

创建用户

client * get_client(int index);

获取用户

typedef void(*handle_iterator_client)(std::map<int, client*> & set)

void iterator_client_set(handle_iterator_client fn);

void iterator_client_set(std::function<void(std::map<int, client*> &) > fn);

遍历用户

bool destroy_client(int index);

删除用户

int client_count();

获取用户数目


例子:fossilizid/test/test_vchat


 

fossilizid简介

标签:

原文地址:http://www.cnblogs.com/qianqians/p/4214401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!