secgateway/Platform/common/redismq/redis_subscriber.h

52 lines
1.0 KiB
C

#ifndef REDIS_SUBSCRIBER_H
#define REDIS_SUBSCRIBER_H
#include <stdlib.h>
#include <hiredis/async.h>
#include <hiredis/adapters/libevent.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdbool.h>
#include "thpool.h"
extern struct RedisSubscriber gRedisSubscriber;
extern struct json_object* gJsonObj;
extern threadpool gThpool;
struct RedisSubscriber
{
/*libevent事件对象*/
struct event_base *eventBase;
/*事件线程ID*/
pthread_t eventThread;
/* 事件线程的信号量*/
sem_t eventSem;
/* hiredis异步对象*/
redisAsyncContext *redisContext;
// 通知外层的回调函数对象
//NotifyMessageFn _notify_message_fn;
};
struct RecvMsg_t
{
char *msg;
int len;
};
bool redisSubInit();
void redisSubUninit();
void redisSubDisconnect();
bool redisSubConnect();
bool redisSubscriber(char * channel_name);
typedef void(*pChanneCallBack)(struct RecvMsg_t *msg);
void redisRegisterChannelFunc(char *channel, pChanneCallBack func);
void freeMsg(struct RecvMsg_t *pMsg);
#endif