提交 b23ec880 authored 作者: João Mesquita's avatar João Mesquita

* Added the KChannel -> session relationship so I always know what is what

* Added handlers for almost all events sent by the board
* Cleaned up the code a little bit more


git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/scripts/contrib@13778 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 07073e9c
MODNAME=mod_khomp
LOCAL_CFLAGS=-I./include -I./commons/include -lk3l -D_REENTRANT -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DK3L_HOSTSYSTEM -DKHOMP_COMMONS_WITH_CHANNEL
LOCAL_CFLAGS=-I./include -I./commons/include -lk3l -D_REENTRANT -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DK3L_HOSTSYSTEM
LOCAL_OBJS= ./commons/k3lapi.o
......
#include <string>
#include <k3l.h>
#ifndef KHOMP_COMMONS_WITH_CHANNEL
# include <k3lVersion.h>
#endif
#include <k3lVersion.h>
#ifdef __GNUC_PREREQ
#if __GNUC_PREREQ(4,3)
......@@ -15,6 +12,12 @@
#ifndef INCLUDED_K3LAPI_HPP
#define INCLUDED_K3LAPI_HPP
/* FreeSWITCH include */
extern "C" {
#include "switch.h"
}
struct K3LAPI
{
/* exceptions */
......@@ -78,12 +81,29 @@ struct K3LAPI
std::string name;
KLibraryStatus rc;
};
struct KChannel {
public:
KChannel() : _session(NULL){};
void setSession(switch_core_session_t * session)
{
_session = session;
}
switch_core_session_t * getSession()
{
return _session;
}
protected:
switch_core_session_t * _session;
};
typedef K3L_DEVICE_CONFIG device_conf_type;
typedef K3L_CHANNEL_CONFIG channel_conf_type;
typedef K3L_CHANNEL_CONFIG * channel_ptr_conf_type;
typedef K3L_LINK_CONFIG link_conf_type;
typedef K3L_LINK_CONFIG * link_ptr_conf_type;
typedef KChannel KChannel_t;
typedef KChannel_t * KChannel_ptr_t;
/* constructors/destructors */
......@@ -186,12 +206,27 @@ struct K3LAPI
void init(void);
void setSession(unsigned int boardId, unsigned int chanId, switch_core_session_t * session)
{
if (!valid_channel(boardId, chanId))
throw invalid_channel(boardId, chanId);
_KChannel[boardId][chanId].setSession(session);
}
switch_core_session_t * getSession(unsigned int boardId, unsigned int chanId)
{
if (!valid_channel(boardId, chanId))
throw invalid_channel(boardId, chanId);
return _KChannel[boardId][chanId].getSession();
}
protected:
unsigned int _device_count;
unsigned int * _channel_count;
unsigned int * _link_count;
unsigned int _device_count;
unsigned int * _channel_count;
unsigned int * _link_count;
KChannel_ptr_t * _KChannel;
device_conf_type * _device_config;
channel_ptr_conf_type * _channel_config;
link_ptr_conf_type * _link_config;
......
......@@ -22,7 +22,7 @@ K3LAPI::~K3LAPI()
void K3LAPI::start(void)
{
/* tie the used k3l to the compiled k3l version */
char *ret = k3lStart(k3lApiMajorVersion, k3lApiMinorVersion, 0); //k3lApiBuildVersion);
char *ret = k3lStart(2, 0, 0); //k3lApiMajorVersion, k3lApiMinorVersion, 0); //k3lApiBuildVersion);
if (ret && *ret)
throw start_failed(ret);
......@@ -129,6 +129,7 @@ void K3LAPI::init(void)
_device_type = new KDeviceType[_device_count];
_device_config = new device_conf_type[_device_count];
_channel_config = new channel_ptr_conf_type[_device_count];
_KChannel = new KChannel_ptr_t[_device_count];
_link_config = new link_ptr_conf_type[_device_count];
_channel_count = new unsigned int[_device_count];
_link_count = new unsigned int[_device_count];
......@@ -147,12 +148,15 @@ void K3LAPI::init(void)
/* caches each channel config */
_channel_config[dev] = new channel_conf_type[_channel_count[dev]];
_KChannel[dev] = new KChannel_t[_channel_count[dev]];
for (unsigned int obj = 0; obj < _channel_count[dev]; obj++)
{
if (k3lGetDeviceConfig(dev, ksoChannel + obj, &(_channel_config[dev][obj]),
sizeof(_channel_config[dev][obj])) != ksSuccess)
{
throw start_failed("k3lGetDeviceConfig(channel)");
}
}
/* adjust link count for device */
......
#ifndef k3lVersion_h
#define k3lVersion_h
#define k3lApiMajorVersion 2
#define k3lApiMinorVersion 0
#define k3lApiBuildVersion 0
#endif
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论