[Freeswitch-svn] [commit] r13990 - in freeswitch/trunk/contrib/mod/endpoints/mod_khomp: commons include

FreeSWITCH SVN raulfragoso at freeswitch.org
Fri Jun 26 16:24:24 PDT 2009


Author: raulfragoso
Date: Fri Jun 26 18:24:24 2009
New Revision: 13990

Log:
More files from Khomp

Added:
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/commons/strings.hpp
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/commons/types.hpp
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/globals.h
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/k3lDefs.h
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/mod_khomp.h
   freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/opt.h

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/commons/strings.hpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/commons/strings.hpp	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,63 @@
+#include <limits.h>
+
+#include <list>
+#include <vector>
+#include <string>
+
+#include <format.hpp>
+
+#include <types.hpp>
+
+/* Generic string funcions */
+
+#ifndef INCLUDED_STRINGS_HPP
+#define INCLUDED_STRINGS_HPP
+
+struct Strings
+{
+    typedef std::list<std::string>      list_type;
+    typedef std::vector<std::string>  vector_type;
+
+    struct Merger
+    {
+        void          add(std::string);
+
+        std::string merge(const std::string &);
+        std::string merge(const char *);
+
+        bool empty() { return _list.empty(); };
+        
+     protected:
+        list_type   _list;
+    };
+
+ public:
+    struct invalid_value
+    {
+        invalid_value(const char  * value): _value(value) {};
+        invalid_value(std::string   value): _value(value) {};
+
+        std::string & value() { return _value; }
+        
+     protected:
+         std::string _value;
+    };
+    
+    struct not_implemented {};
+
+    static void tokenize(const std::string &, vector_type &, const std::string & delims = ",;:", long int max_toxens = LONG_MAX);
+
+    static bool        toboolean(std::string);
+    static std::string fromboolean(bool);
+
+    static long               tolong(std::string, int base = 10);
+    static unsigned long      toulong(std::string, int base = 10);
+    static unsigned long long toulonglong(std::string, int base = 10);
+
+    static std::string lower(std::string);
+    static std::string hexadecimal(std::string);
+    
+    static std::string trim(const std::string&, const std::string& trim_chars = " \f\n\r\t\v");
+};
+
+#endif // INCLUDED_STRINGS_HPP //

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/commons/types.hpp
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/commons/types.hpp	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,169 @@
+#ifndef INCLUDED_TYPES_HPP
+#define INCLUDED_TYPES_HPP
+
+#if defined(LINUX) || defined(__LINUX__) || defined(__linux__) 
+#include <stdlib.h> 
+#endif 
+
+/*** Used for conditional compilation based on K3L version ***/
+
+#define K3L_AT_LEAST(major,minor,build) \
+    (((k3lApiMajorVersion == major) && ((k3lApiMinorVersion == minor) && (k3lApiBuildVersion >= build)) || \
+     ((k3lApiMajorVersion == major) && (k3lApiMinorVersion > minor))) || \
+      (k3lApiMajorVersion  > major))
+
+#define K3L_EXACT(major,minor,build) \
+    ((k3lApiMajorVersion == major) && (k3lApiMinorVersion == minor) && (k3lApiBuildVersion >= build))
+
+/**** Used for indexing any kind of Khomp object. ****/
+
+typedef unsigned short int   ushort;
+
+template <class value_type>
+struct ktype_id
+{
+    ktype_id(value_type id): _id(id) {};
+
+    value_type id(void) { return _id; };
+    
+ protected:
+     value_type _id;
+};
+
+struct deviceId:  ktype_id<ushort> { deviceId(ushort id):  ktype_id<ushort>(id) {}; };
+struct channelId: ktype_id<ushort> { channelId(ushort id): ktype_id<ushort>(id) {}; };
+struct playerId:  ktype_id<ushort> { playerId(ushort id):  ktype_id<ushort>(id) {}; };
+struct mixerId:   ktype_id<ushort> { mixerId(ushort id):   ktype_id<ushort>(id) {}; };
+struct linkId:    ktype_id<ushort> { linkId(ushort id):    ktype_id<ushort>(id) {}; };
+
+struct kobject
+{
+    struct hash;
+    struct less;
+    struct equal;
+    struct hashLess;
+
+    struct item
+    {
+        typedef enum
+        {
+            DEVICE  = 1,
+            CHANNEL = 2,
+            PLAYER  = 3,
+            MIXER   = 4,
+            LINK    = 5,
+        }
+        type_t;
+
+        item(deviceId dev)
+        {
+            _type = DEVICE;
+            _dev = dev.id();
+            _obj = 0xffff;
+        };
+
+        item(deviceId dev, channelId chan)
+        {
+            _type = CHANNEL;
+            _dev = dev.id();
+            _obj = chan.id();
+        };
+
+        item(deviceId dev, playerId play)
+        {
+            _type = PLAYER;
+            _dev = dev.id();
+            _obj = play.id();
+        };
+
+        item(deviceId dev, mixerId mix)
+        {
+            _type = MIXER;
+            _dev = dev.id();
+            _obj = mix.id();
+        };
+
+        item(deviceId dev, linkId lnk)
+        {
+            _type = LINK;
+            _dev = dev.id();
+            _obj = lnk.id();
+        };
+
+        type_t    type() { return _type; };
+        ushort  device() { return _dev; };
+        ushort  object() { return _obj; };
+
+     protected:
+        type_t _type;
+        ushort _dev;
+        ushort _obj;
+
+     private:
+        item();
+
+     friend struct kobject::hash;
+     friend struct kobject::less;
+     friend struct kobject::equal;
+     friend struct kobject::hashLess;
+    };
+
+    struct hash
+    {
+        size_t operator()(const item &i) const
+        {
+            return (((ushort) (i._type)) << 28) + ((i._dev) << 16) + (i._obj);
+        }
+    };
+
+    struct equal
+    {
+        bool operator()(const item &i1, const item &i2) const
+        {
+            return
+                ((i1._type == i2._type) &&
+                 (i1._dev  == i2._dev)  &&
+                 (i1._obj  == i2._obj));
+        }
+    };
+
+    struct less
+    {
+        bool comp(const item &i1, const item &i2) const
+        {
+            if (i1._type < i2._type)
+                return true;
+
+            if (i1._type == i2._type)
+            {
+                if (i1._dev  < i2._dev)
+                    return true;
+
+                if (i1._dev == i2._dev)
+                {
+                    if (i1._obj  < i2._obj)
+                        return true;
+                    else
+                        return false;
+                }
+            }
+
+            return false;
+        }
+
+        bool operator()(const item &i1, const item &i2) const
+        {
+            return comp(i1,i2);
+        }
+    };
+
+    struct hashLess
+    : public hash, public less
+    {
+         public:
+            static const size_t bucket_size = 4;
+            static const size_t min_buckets = 8;
+    };
+};
+
+#endif /* INCLUDED_TYPES_HPP */

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/globals.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/globals.h	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,38 @@
+#ifndef _GLOBALS_H_
+#define _GLOBALS_H_
+
+#include "k3lapi.hpp"
+
+#include <config_options.hpp>
+
+#include <vector>
+
+extern "C"
+{
+    #include <switch.h>
+}
+
+
+struct Globals
+{
+
+    static K3LAPI _k3lapi;
+
+    /* Config options class */
+    static config_options _options;
+
+
+
+    static switch_endpoint_interface_t *_khomp_endpoint_interface;
+    static switch_api_interface_t *_api_interface;
+    static switch_memory_pool_t *_module_pool;
+    static int _running;
+
+    static unsigned int _flags;
+    static int _calls;
+    static switch_mutex_t *_mutex;
+
+};
+
+
+#endif /* _GLOBALS_H_ */

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/k3lDefs.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/k3lDefs.h	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,66 @@
+/*  
+    KHOMP endpoint provider for FreeSWITCH(tm)
+    Copyright (C) 2007-2009 Khomp Ind. & Com.  
+  
+  The contents of this file are subject to the Mozilla Public License Version 1.1
+  (the "License"); you may not use this file except in compliance with the
+  License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
+
+  Software distributed under the License is distributed on an "AS IS" basis,
+  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+  the specific language governing rights and limitations under the License.
+
+  Alternatively, the contents of this file may be used under the terms of the
+  "GNU Lesser General Public License 2.1" license (the “LGPL" License), in which
+  case the provisions of "LGPL License" are applicable instead of those above.
+
+  If you wish to allow use of your version of this file only under the terms of
+  the LGPL License and not to allow others to use your version of this file under
+  the MPL, indicate your decision by deleting the provisions above and replace them
+  with the notice and other provisions required by the LGPL License. If you do not
+  delete the provisions above, a recipient may use your version of this file under
+  either the MPL or the LGPL License.
+
+  The LGPL header follows below:
+
+    This library is free software; you can redistribute it and/or  
+    modify it under the terms of the GNU Lesser General Public  
+    License as published by the Free Software Foundation; either  
+    version 2.1 of the License, or (at your option) any later version.  
+  
+    This library is distributed in the hope that it will be useful,  
+    but WITHOUT ANY WARRANTY; without even the implied warranty of  
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  
+    Lesser General Public License for more details.  
+  
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
+  
+*/
+
+#ifndef INCLUDED_K3LDEFS_H
+#define INCLUDED_K3LDEFS_H
+
+enum KISDNDebugFlag
+{
+    kidfQ931                        = 0x01,
+    kidfLAPD                        = 0x02,
+    kidfSystem                      = 0x04,
+    kidfInvalid                     = 0x08,
+};
+
+#define CM_VOIP_START_DEBUG      0x20
+#define CM_VOIP_STOP_DEBUG       0x21
+#define CM_VOIP_DUMP_STAT        0x22
+
+#define CM_ISDN_DEBUG            0x24
+
+#define CM_PING     0x123456
+#define EV_PONG     0x654321
+
+#define CM_LOG_REQUEST                  0x100
+#define CM_LOG_CREATE_DISPATCHER        0x101
+#define CM_LOG_DESTROY_DISPATCHER       0x102
+
+#endif /* INCLUDED_K3LDEFS_H */

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,80 @@
+#ifndef _KHOMP_PVT_H_
+#define _KHOMP_PVT_H_
+
+#include "globals.h"
+
+struct KhompPvt
+{
+
+    typedef std::vector < KhompPvt * >        PvtVectorType;
+    typedef std::vector < PvtVectorType >   PvtVector2Type;
+    typedef PvtVector2Type KhompPvtVector;
+    
+    KhompPvt(K3LAPI::target & target)
+    : _target(target), _session(NULL) {};
+
+    K3LAPI::target target()
+    {
+        return _target;
+    }
+    
+    void session(switch_core_session_t * newSession)
+    {
+        _session = newSession;
+    }
+
+    switch_core_session_t * session()
+    {
+        return _session;
+    }
+
+    static KhompPvt * khompPvt(int32 device, int32 object)
+    {
+        if (!Globals::_k3lapi.valid_channel(device, object))
+            throw K3LAPI::invalid_channel(device, object);
+
+        return _pvts[device][object];
+    }
+
+    static KhompPvt * khompPvt(K3LAPI::target & target)
+    {
+        return _pvts[target.device][target.object];
+    }
+
+    static void initialize(void)
+    {
+
+////        tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))
+        //for (unsigned dev = 0; dev < Globals::_k3lapi.device_count(); dev++)
+        //{
+         //   _pvts.push_back(std::vector<KhompPvt>());
+
+            //for (unsigned obj = 0; obj < Globals::_k3lapi.channel_count(obj); obj++)
+                //_pvts.back().push_back(KhompPvt(K3LAPI::target(Globals::_k3lapi, K3LAPI::target::CHANNEL, dev, obj)));
+       // }
+    }
+
+    K3LAPI::target          _target;
+    switch_core_session_t * _session;
+
+    unsigned int flags; //TODO: Alterar o nome depois
+
+    switch_codec_t _read_codec;
+    switch_codec_t _write_codec;
+
+    switch_frame_t _read_frame;
+
+    unsigned char _databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+
+    switch_caller_profile_t *_caller_profile;
+
+    switch_mutex_t *_mutex;
+    switch_mutex_t *flag_mutex; //TODO: Alterar o nome depois
+
+    /* static stuff */    
+    static KhompPvtVector _pvts;
+};
+
+
+
+#endif /* _KHOMP_PVT_H_*/

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/mod_khomp.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/mod_khomp.h	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,10 @@
+#ifndef _MOD_KHOMP_H_
+#define _MOD_KHOMP_H_
+
+#include "globals.h"
+#include "khomp_pvt.h"
+#include "opt.h"
+
+
+
+#endif /* _MOD_KHOMP_H_ */

Added: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/opt.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/opt.h	Fri Jun 26 18:24:24 2009
@@ -0,0 +1,42 @@
+#ifndef _OPT_H_
+#define _OPT_H_
+
+struct Opt
+{
+
+    typedef enum {
+            GFLAG_MY_CODEC_PREFS = (1 << 0)
+    } GFLAGS;
+
+
+    static void initialize(void);
+    static void obtain(void);
+
+
+protected:
+
+    static void load_configuration(const char *, const char **, bool show_errors = true);
+    static void clean_configuration(void);
+
+
+public:
+    static bool _debug;
+    static char *_ip;
+    static int _port;
+    static char *_dialplan;
+    static char *_codec_string;
+    static char *_codec_order[]; //[SWITCH_MAX_CODECS]
+    static int _codec_order_last;
+    static char *_codec_rates_string;
+    static char *_codec_rates[]; //[SWITCH_MAX_CODECS]
+    static int _codec_rates_last;
+
+
+
+};
+
+
+
+
+
+#endif /* _OPT_H_ */



More information about the Freeswitch-svn mailing list