Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

yatepbx.h

00001 /*
00002  * yatepbx.h
00003  * This file is part of the YATE Project http://YATE.null.ro
00004  *
00005  * Common C++ base classes for PBX related plugins
00006  *
00007  * Yet Another Telephony Engine - a fully featured software PBX and IVR
00008  * Copyright (C) 2004-2006 Null Team
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
00023  */
00024 
00025 #include <yatephone.h>
00026 
00027 #ifdef _WINDOWS
00028 
00029 #ifdef LIBYPBX_EXPORTS
00030 #define YPBX_API __declspec(dllexport)
00031 #else
00032 #ifndef LIBYPBX_STATIC
00033 #define YPBX_API __declspec(dllimport)
00034 #endif
00035 #endif
00036 
00037 #endif /* _WINDOWS */
00038 
00039 #ifndef YPBX_API
00040 #define YPBX_API
00041 #endif
00042 
00043 namespace TelEngine {
00044 
00048 class YPBX_API CallInfo : public NamedList
00049 {
00050 public:
00051     inline CallInfo(const char* name, CallEndpoint* call = 0)
00052         : NamedList(name), m_call(call)
00053         { }
00054 
00055     virtual ~CallInfo()
00056         { m_call = 0; }
00057 
00058     inline CallEndpoint* call() const
00059         { return m_call; }
00060 
00061     inline void setCall(CallEndpoint* call)
00062         { m_call = call; }
00063 
00064     inline void clearCall()
00065         { m_call = 0; }
00066 
00070     bool copyParam(const NamedList& original, const String& name, bool clear = false);
00071 
00075     void copyParams(const NamedList& original, bool clear, ...);
00076     void fillParam(NamedList& target, const String& name, bool clear = false);
00077     void fillParams(NamedList& target);
00078 
00079 protected:
00080     CallEndpoint* m_call;
00081     int m_route;
00082 };
00083 
00087 class YPBX_API CallList
00088 {
00089 public:
00090     inline void append(CallInfo* call)
00091         { m_calls.append(call); }
00092     inline void remove(CallInfo* call)
00093         { m_calls.remove(call,false); }
00094     CallInfo* find(const String& id);
00095     CallInfo* find(const CallEndpoint* call);
00096 protected:
00097     ObjList m_calls;
00098 };
00099 
00100 class YPBX_API MultiRouter : public MessageReceiver
00101 {
00102 public:
00103     enum {
00104         Route,
00105         Execute,
00106         Hangup,
00107         Disconnected
00108     };
00109     MultiRouter();
00110     virtual ~MultiRouter();
00111     void setup(int priority = 0);
00112     virtual bool received(Message& msg, int id);
00113     virtual bool msgRoute(Message& msg, CallInfo& info, bool first);
00114     virtual bool msgExecute(Message& msg, CallInfo& info, bool first);
00115     virtual bool msgDisconnected(Message& msg, CallInfo& info);
00116     virtual void msgHangup(Message& msg, CallInfo& info);
00117     virtual Message* buildExecute(CallInfo& info, bool reroute) = 0;
00118     Message* defaultExecute(CallInfo& info, const char* route = 0);
00119 protected:
00120     CallList m_list;
00121     Mutex m_mutex;
00122 private:
00123     MessageRelay* m_relRoute;
00124     MessageRelay* m_relExecute;
00125     MessageRelay* m_relHangup;
00126     MessageRelay* m_relDisconnected;
00127 };
00128 
00129 class ChanAssistList;
00130 
00134 class YPBX_API ChanAssist :  public RefObject
00135 {
00136 public:
00140     virtual ~ChanAssist();
00141 
00146     virtual const String& toString() const
00147         { return m_chanId; }
00148 
00153     virtual void msgStartup(Message& msg);
00154 
00159     virtual void msgHangup(Message& msg);
00160 
00166     virtual bool msgDisconnect(Message& msg, const String& reason);
00167 
00172     inline ChanAssistList* list() const
00173         { return m_list; }
00174 
00179     inline const String& id() const
00180         { return m_chanId; }
00181 
00187     static RefPointer<CallEndpoint> locate(const String& id);
00188 
00193     inline RefPointer<CallEndpoint> locate() const
00194         { return locate(m_chanId); }
00195 
00196 protected:
00202     inline ChanAssist(ChanAssistList* list, const String& id)
00203         : m_list(list), m_chanId(id)
00204         { }
00205 private:
00206     ChanAssist(); // no default constructor please
00207     ChanAssistList* m_list;
00208     String m_chanId;
00209 };
00210 
00215 class YPBX_API ChanAssistList : public Module
00216 {
00217     friend class ChanAssist;
00218 public:
00222     enum {
00223         Startup = Private,
00224         Hangup,
00225         Disconnected,
00226         AssistPrivate
00227     };
00228 
00232     virtual ~ChanAssistList()
00233         { }
00234 
00241     virtual bool received(Message& msg, int id);
00242 
00250     virtual bool received(Message& msg, int id, ChanAssist* assist);
00251 
00255     virtual void initialize();
00256 
00263     virtual ChanAssist* create(Message& msg, const String& id) = 0;
00264 
00269     virtual void init(int priority = 15);
00270 
00276     inline ChanAssist* find(const String& id) const
00277         { return static_cast<ChanAssist*>(m_calls[id]); }
00278 
00279 protected:
00284     inline ChanAssistList(const char* name)
00285         : Module(name, "misc"), m_first(true)
00286         { }
00287 
00292     void removeAssist(ChanAssist* assist);
00293 
00294 private:
00295     ChanAssistList(); // no default constructor please
00296     HashList m_calls;
00297     bool m_first;
00298 };
00299 
00300 }
00301 /* vi: set ts=8 sw=4 sts=4 noet: */

Generated on Mon Sep 18 20:56:12 2006 for Yate by  doxygen 1.4.4