Yate
|
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, public Mutex 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 private: 00122 MessageRelay* m_relRoute; 00123 MessageRelay* m_relExecute; 00124 MessageRelay* m_relHangup; 00125 MessageRelay* m_relDisconnected; 00126 }; 00127 00128 class ChanAssistList; 00129 00133 class YPBX_API ChanAssist : public RefObject 00134 { 00135 public: 00139 virtual ~ChanAssist(); 00140 00145 virtual const String& toString() const 00146 { return m_chanId; } 00147 00152 virtual void msgStartup(Message& msg); 00153 00158 virtual void msgHangup(Message& msg); 00159 00164 virtual void msgExecute(Message& msg); 00165 00171 virtual bool msgDisconnect(Message& msg, const String& reason); 00172 00177 inline ChanAssistList* list() const 00178 { return m_list; } 00179 00184 inline const String& id() const 00185 { return m_chanId; } 00186 00192 static RefPointer<CallEndpoint> locate(const String& id); 00193 00198 inline RefPointer<CallEndpoint> locate() const 00199 { return locate(m_chanId); } 00200 00201 protected: 00207 inline ChanAssist(ChanAssistList* list, const String& id) 00208 : m_list(list), m_chanId(id) 00209 { } 00210 private: 00211 ChanAssist(); // no default constructor please 00212 ChanAssistList* m_list; 00213 String m_chanId; 00214 }; 00215 00220 class YPBX_API ChanAssistList : public Module 00221 { 00222 friend class ChanAssist; 00223 public: 00227 enum { 00228 Startup = Private, 00229 Hangup, 00230 Disconnected, 00231 AssistPrivate 00232 }; 00233 00237 virtual ~ChanAssistList() 00238 { } 00239 00246 virtual bool received(Message& msg, int id); 00247 00255 virtual bool received(Message& msg, int id, ChanAssist* assist); 00256 00260 virtual void initialize(); 00261 00268 virtual ChanAssist* create(Message& msg, const String& id) = 0; 00269 00274 virtual void init(int priority = 15); 00275 00281 inline ChanAssist* find(const String& id) const 00282 { return static_cast<ChanAssist*>(m_calls[id]); } 00283 00284 protected: 00290 inline ChanAssistList(const char* name, bool earlyInit = false) 00291 : Module(name, "misc", earlyInit), m_first(true) 00292 { } 00293 00298 void removeAssist(ChanAssist* assist); 00299 00304 inline HashList& calls() 00305 { return m_calls; } 00306 00311 inline const HashList& calls() const 00312 { return m_calls; } 00313 00314 private: 00315 ChanAssistList(); // no default constructor please 00316 HashList m_calls; 00317 bool m_first; 00318 }; 00319 00320 } 00321 /* vi: set ts=8 sw=4 sts=4 noet: */