[Freeswitch-trunk] [commit] r13757 - in freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons: . include

FreeSWITCH SVN jmesquita at freeswitch.org
Thu Jun 11 09:10:53 PDT 2009


Author: jmesquita
Date: Thu Jun 11 11:10:52 2009
New Revision: 13757

Log:
Forgot to add a few things b4 commit

Added:
   freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/
   freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/include/
   freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/include/k3lapi.hpp
   freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/k3lapi.cpp

Added: freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/include/k3lapi.hpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/include/k3lapi.hpp	Thu Jun 11 11:10:52 2009
@@ -0,0 +1,201 @@
+#include <string>
+
+#include <k3l.h>
+
+#ifndef KHOMP_COMMONS_WITH_CHANNEL
+# include <k3lVersion.h>
+#endif
+
+#ifdef __GNUC_PREREQ
+#if __GNUC_PREREQ(4,3)
+#include <cstring>
+#endif
+#endif
+
+#ifndef INCLUDED_K3LAPI_HPP
+#define INCLUDED_K3LAPI_HPP
+
+struct K3LAPI
+{
+	/* exceptions */
+
+	struct start_failed
+	{
+		start_failed(const char * _msg) : msg(_msg) {};
+		std::string msg;
+	};
+	
+	struct failed_command
+	{
+		failed_command(int32 _code, unsigned int _dev, unsigned int _obj, int32 _rc)
+		: code(_code), dev(_dev), obj(_obj), rc(_rc) {};
+		
+		int32         code;
+		unsigned int  dev;
+		unsigned int  obj;
+		int32         rc;
+	};
+
+	struct failed_raw_command
+	{
+		failed_raw_command(unsigned int _dev, unsigned int _dsp, int32 _rc)
+		: dev(_dev), dsp(_dsp), rc(_rc) {};
+		
+		unsigned int  dev;
+		unsigned int  dsp;
+		int32         rc;
+	};
+
+	struct invalid_device
+	{
+		invalid_device(unsigned int _device)
+		: device(_device) {};
+		
+		unsigned int device;
+	};
+
+	struct invalid_channel
+	{
+		invalid_channel(unsigned int _device, unsigned int _channel)
+		: device(_device), channel(_channel) {};
+
+		unsigned int device, channel;
+	};
+
+	struct invalid_link
+	{
+		invalid_link(unsigned int _device, unsigned int _link)
+		: device(_device), link(_link) {};
+
+		unsigned int device, link;
+	};
+
+	struct get_param_failed
+	{
+		get_param_failed(std::string _name, int32 _rc)
+		: name(_name), rc((KLibraryStatus)_rc) {};
+
+		std::string name;
+		KLibraryStatus rc;
+	};
+	
+	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;
+
+	/* constructors/destructors */
+	
+	K3LAPI();
+	~K3LAPI();
+
+	/* (init|final)ialize the whole thing! */
+	
+	void start(void);
+	void stop(void);
+
+	/* verificacao de intervalos */
+	
+	inline bool valid_device( unsigned int dev )
+	{
+    	return (dev < _device_count);
+	}
+
+	inline bool valid_channel( unsigned int dev, unsigned int obj )
+	{
+	    return (valid_device(dev) && obj < _channel_count[dev]);
+	}
+
+	inline bool valid_link( unsigned int dev, unsigned int obj )
+	{
+	    return (valid_device(dev) && obj < _link_count[dev]);
+	}
+
+	/* envio de comandos para placa */
+	
+	void mixer(int32 dev, int32 obj, byte track, KMixerSource src, int32 index);
+	void mixerCTbus(int32 dev, int32 obj, byte track, KMixerSource src, int32 index);
+	void command (int32 dev, int32 obj, int32 code, std::string & str);
+	void command (int32 dev, int32 obj, int32 code, const char * parms = NULL);
+	void raw_command(int32 dev, int32 dsp, std::string & str);
+	void raw_command(int32 dev, int32 dsp, const char * cmds, int32 size);
+
+	/* obter dados 'cacheados' */
+	
+	inline unsigned int device_count(void)
+	{
+		return _device_count;
+	}
+
+	inline unsigned int channel_count(unsigned int dev)
+	{
+		if (!valid_device(dev))
+			throw invalid_device(dev);
+
+		return _channel_count[dev];
+	}
+
+	inline unsigned int link_count(unsigned int dev)
+	{
+		if (!valid_device(dev))
+			throw invalid_device(dev);
+
+		return _link_count[dev];
+	}
+
+	KDeviceType device_type(unsigned int dev)
+	{
+		if (!valid_device(dev))
+			throw invalid_device(dev);
+		
+		return _device_type[dev];
+	}
+	
+
+	K3L_DEVICE_CONFIG & device_config(unsigned int dev)
+	{
+		if (!valid_device(dev))
+			throw invalid_device(dev);
+
+		return _device_config[dev];
+	}
+
+	K3L_CHANNEL_CONFIG & channel_config(unsigned int dev, unsigned int obj)
+	{
+		if (!valid_channel(dev, obj))
+			throw invalid_channel(dev, obj);
+
+		return _channel_config[dev][obj];
+	}
+
+	K3L_LINK_CONFIG & link_config(unsigned int dev, unsigned int obj)
+	{
+		if (!valid_channel(dev, obj))
+			throw invalid_channel(dev, obj);
+
+		return _link_config[dev][obj];
+	}
+
+	/* pega valores em strings de eventos */
+
+	KLibraryStatus get_param(K3L_EVENT *ev, const char *name, std::string &res);
+	std::string get_param(K3L_EVENT *ev, const char *name);
+
+	/* inicializa valores em cache */
+
+	void init(void);
+
+ protected:
+
+	unsigned int           _device_count;
+	unsigned int *        _channel_count;
+	unsigned int *           _link_count;
+	
+	     device_conf_type *   _device_config;
+	channel_ptr_conf_type *  _channel_config;
+	   link_ptr_conf_type *     _link_config;
+	          KDeviceType *     _device_type;
+};
+
+#endif /* INCLUDED_K3LAPI_HPP */

Added: freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/k3lapi.cpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/commons/k3lapi.cpp	Thu Jun 11 11:10:52 2009
@@ -0,0 +1,171 @@
+#include <k3lapi.hpp>
+
+K3LAPI::K3LAPI()
+: _device_count(0),  _channel_count(0),  _link_count(0),
+  _device_config(0), _channel_config(0), _link_config(0)
+{}
+
+K3LAPI::~K3LAPI()
+{
+	_device_count = 0;
+		
+	if (_device_type)    { delete[] _device_type;       _device_type = NULL; }
+	if (_device_config)  { delete[] _device_config;   _device_config = NULL; }
+	if (_channel_config) { delete[] _channel_config; _channel_config = NULL; }
+	if (_link_config)    { delete[] _link_config;       _link_config = NULL; }
+	if (_channel_count)  { delete[] _channel_count;   _channel_count = NULL; }
+	if (_link_count)     { delete[] _link_count;         _link_count = NULL; }
+}
+
+/* initialize the whole thing! */
+	
+void K3LAPI::start(void)
+{
+	/* tie the used k3l to the compiled k3l version */
+	char *ret = k3lStart(k3lApiMajorVersion, k3lApiMinorVersion, 0); //k3lApiBuildVersion);
+	
+	if (ret && *ret)
+		throw start_failed(ret);
+			
+	/* call init automagically */
+	init();
+}
+
+void K3LAPI::stop(void)
+{
+	k3lStop();
+}
+
+/* envio de comandos para placa */
+	
+void K3LAPI::mixer(int32 dev, int32 obj, byte track, KMixerSource src, int32 index)
+{
+   	KMixerCommand mix;
+
+    mix.Track = track;
+   	mix.Source = src;
+    mix.SourceIndex = index;
+
+   	command(dev, obj, CM_MIXER, (const char *) &mix);
+}
+
+void K3LAPI::mixerCTbus(int32 dev, int32 obj, byte track, KMixerSource src, int32 index)
+{
+   	KMixerCommand mix;
+
+    mix.Track = track;
+   	mix.Source = src;
+    mix.SourceIndex = index;
+
+   	command(dev, obj, CM_MIXER_CTBUS, (const char *) &mix);
+}
+
+void K3LAPI::command(int32 dev, int32 obj, int32 code, std::string & str)
+{
+	command(dev, obj, code, str.c_str());
+}
+
+void K3LAPI::command (int32 dev, int32 obj, int32 code, const char * parms)
+{
+    K3L_COMMAND cmd;
+
+   	cmd.Cmd = code;
+    cmd.Object = obj;
+   	cmd.Params = (byte *)parms;
+
+	int32 rc = k3lSendCommand(dev, &cmd);
+		
+	if (rc != ksSuccess)
+		throw failed_command(code, dev, obj, rc);
+}
+
+void K3LAPI::raw_command(int32 dev, int32 dsp, std::string & str)
+{
+	raw_command(dev, dsp, str.data(), str.size());
+}
+
+void K3LAPI::raw_command(int32 dev, int32 dsp, const char * cmds, int32 size)
+{
+    std::string str(cmds, size);
+
+	int32 rc = k3lSendRawCommand(dev, dsp, (void *)cmds, size);
+
+	if (rc != ksSuccess)
+		throw failed_raw_command(dev, dsp, rc);
+}
+
+KLibraryStatus K3LAPI::get_param(K3L_EVENT *ev, const char *name, std::string &res)
+{
+	char tmp_param[256];
+	memset((void*)tmp_param, 0, sizeof(tmp_param));
+
+	int32 rc = k3lGetEventParam (ev, (sbyte *)name, (sbyte *)tmp_param, sizeof(tmp_param)-1);
+		
+	if (rc != ksSuccess)
+		return (KLibraryStatus)rc;
+
+	res.append(tmp_param, strlen(tmp_param));
+	return ksSuccess;
+}
+	
+std::string K3LAPI::get_param(K3L_EVENT *ev, const char *name)
+{
+	std::string res;
+
+	KLibraryStatus rc = get_param(ev, name, res);
+
+	if (rc != ksSuccess)
+		throw get_param_failed(name, rc);
+			
+	return res;
+}
+
+void K3LAPI::init(void)
+{
+	if (_device_count != 0) return;
+
+	_device_count = k3lGetDeviceCount();
+
+	_device_type	= new KDeviceType[_device_count];
+	_device_config  = new device_conf_type[_device_count];
+	_channel_config = new channel_ptr_conf_type[_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];
+		
+	for (unsigned int dev = 0; dev < _device_count; dev++)
+	{
+		_device_type[dev] = (KDeviceType) k3lGetDeviceType(dev);
+			
+		/* caches each device config */
+		if (k3lGetDeviceConfig(dev, ksoDevice + dev, &(_device_config[dev]), sizeof(_device_config[dev])) != ksSuccess)
+			throw start_failed("k3lGetDeviceConfig(device)");
+
+		/* adjust channel/link count for device */
+		_channel_count[dev] = _device_config[dev].ChannelCount;
+		_link_count[dev] = _device_config[dev].LinkCount;
+			
+		/* caches each channel config */
+		_channel_config[dev] = new channel_conf_type[_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 */
+		_link_count[dev] = _device_config[dev].LinkCount;
+			
+		/* caches each link config */
+		_link_config[dev] = new link_conf_type[_link_count[dev]];
+
+		for (unsigned int obj = 0; obj < _link_count[dev]; obj++)
+		{
+			if (k3lGetDeviceConfig(dev, ksoLink + obj, &(_link_config[dev][obj]), 
+									sizeof(_link_config[dev][obj])) != ksSuccess)
+				throw start_failed("k3lGetDeviceConfig(link)");
+		}
+	}
+}



More information about the Freeswitch-trunk mailing list