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

yatecbase.h

00001 /*
00002  * yatecbase.h
00003  * This file is part of the YATE Project http://YATE.null.ro
00004  *
00005  * Common base classes for all telephony clients
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 #ifndef __YATECBASE_H
00026 #define __YATECBASE_H
00027 
00028 #ifndef __cplusplus
00029 #error C++ is required
00030 #endif
00031                                                                                 
00032 #include <yatephone.h>
00033 
00037 namespace TelEngine {
00038 
00039 class Client;
00040 class ClientChannel;
00041 class ClientDriver;
00042 
00048 class YATE_API Window : public GenObject
00049 {
00050     friend class Client;
00051 public:
00056     Window(const char* id = 0);
00057 
00061     virtual ~Window();
00062 
00067     virtual const String& toString() const;
00068 
00069     /*
00070      * Get the window's title (may not be displayed on screen)
00071      * @return Title of this window
00072      */
00073     virtual void title(const String& text);
00074 
00079     virtual void context(const String& text);
00080 
00086     virtual bool setParams(const NamedList& params);
00087 
00092     virtual void setOver(const Window* parent) = 0;
00093 
00099     virtual bool hasElement(const String& name) = 0;
00100 
00107     virtual bool setActive(const String& name, bool active) = 0;
00108 
00115     virtual bool setFocus(const String& name, bool select = false) = 0;
00116 
00123     virtual bool setShow(const String& name, bool visible) = 0;
00124 
00131     virtual bool setText(const String& name, const String& text) = 0;
00132 
00139     virtual bool setCheck(const String& name, bool checked) = 0;
00140 
00147     virtual bool setSelect(const String& name, const String& item) = 0;
00148 
00155     virtual bool setUrgent(const String& name, bool urgent) = 0;
00156 
00163     virtual bool hasOption(const String& name, const String& item) = 0;
00164 
00173     virtual bool addOption(const String& name, const String& item, bool atStart = false, const String& text = String::empty()) = 0;
00174 
00181     virtual bool delOption(const String& name, const String& item) = 0;
00182 
00183     virtual bool addTableRow(const String& name, const String& item, const NamedList* data = 0, bool atStart = false);
00184     virtual bool delTableRow(const String& name, const String& item);
00185     virtual bool setTableRow(const String& name, const String& item, const NamedList* data);
00186     virtual bool getTableRow(const String& name, const String& item, NamedList* data = 0);
00187     virtual bool clearTable(const String& name);
00188     virtual bool getText(const String& name, String& text) = 0;
00189     virtual bool getCheck(const String& name, bool& checked) = 0;
00190     virtual bool getSelect(const String& name, String& item) = 0;
00191     virtual void populate() = 0;
00192     virtual void init() = 0;
00193     virtual void show() = 0;
00194     virtual void hide() = 0;
00195     virtual void size(int width, int height) = 0;
00196     virtual void move(int x, int y) = 0;
00197     virtual void moveRel(int dx, int dy) = 0;
00198     virtual bool related(const Window* wnd) const;
00199     virtual void menu(int x, int y) = 0;
00200 
00205     inline const String& id() const
00206         { return m_id; }
00207 
00208     /*
00209      * Get the window's title (may not be displayed on screen)
00210      * @return Title of this window
00211      */
00212     inline const String& title() const
00213         { return m_title; }
00214 
00219     inline const String& context() const
00220         { return m_context; }
00221 
00226     inline bool visible() const
00227         { return m_visible; }
00228 
00233     inline void visible(bool yes)
00234         { if (yes) show(); else hide(); }
00235 
00240     inline bool master() const
00241         { return m_master; }
00242 
00247     inline bool popup() const
00248         { return m_popup; }
00249 
00250 protected:
00251     String m_id;
00252     String m_title;
00253     String m_context;
00254     bool m_visible;
00255     bool m_master;
00256     bool m_popup;
00257 };
00258 
00263 class YATE_API UIFactory : public String
00264 {
00265 public:
00266     UIFactory(const char* type, const char* name);
00267     virtual ~UIFactory();
00268 };
00269 
00274 class YATE_API Client : public Thread
00275 {
00276     friend class Window;
00277     friend class ClientChannel;
00278     friend class ClientDriver;
00279 public:
00280     Client(const char *name = 0);
00281     virtual ~Client();
00282     virtual void run();
00283     virtual void main() = 0;
00284     virtual void lock() = 0;
00285     virtual void unlock() = 0;
00286     inline void lockOther()
00287         { if (!m_oneThread) lock(); }
00288     inline void unlockOther()
00289         { if (!m_oneThread) unlock(); }
00290     virtual void allHidden() = 0;
00291     virtual bool createWindow(const String& name) = 0;
00292     virtual bool setStatus(const String& text, Window* wnd = 0);
00293     bool setStatusLocked(const String& text, Window* wnd = 0);
00294     virtual bool action(Window* wnd, const String& name);
00295     virtual bool toggle(Window* wnd, const String& name, bool active);
00296     virtual bool select(Window* wnd, const String& name, const String& item, const String& text = String::empty());
00297     virtual bool callRouting(const String& caller, const String& called, Message* msg = 0);
00298     virtual bool callIncoming(const String& caller, const String& dest = String::empty(), Message* msg = 0);
00299     virtual void updateCDR(const Message& msg);
00300     void clearActive(const String& id);
00301     void callAccept(const char* callId = 0);
00302     void callReject(const char* callId = 0);
00303     void callHangup(const char* callId = 0);
00304     bool callStart(const String& target, const String& line = String::empty(),
00305         const String& proto = String::empty(), const String& account = String::empty());
00306     bool emitDigit(char digit);
00307     inline bool oneThread() const
00308         { return m_oneThread; }
00309     inline int line() const
00310         { return m_line; }
00311     void line(int newLine);
00312     bool hasElement(const String& name, Window* wnd = 0, Window* skip = 0);
00313     bool setActive(const String& name, bool active, Window* wnd = 0, Window* skip = 0);
00314     bool setFocus(const String& name, bool select = false, Window* wnd = 0, Window* skip = 0);
00315     bool setShow(const String& name, bool visible, Window* wnd = 0, Window* skip = 0);
00316     bool setText(const String& name, const String& text, Window* wnd = 0, Window* skip = 0);
00317     bool setCheck(const String& name, bool checked, Window* wnd = 0, Window* skip = 0);
00318     bool setSelect(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00319     bool setUrgent(const String& name, bool urgent, Window* wnd = 0, Window* skip = 0);
00320     bool hasOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00321     bool addOption(const String& name, const String& item, bool atStart, const String& text = String::empty(), Window* wnd = 0, Window* skip = 0);
00322     bool delOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00323     bool addTableRow(const String& name, const String& item, const NamedList* data = 0, bool atStart = false, Window* wnd = 0, Window* skip = 0);
00324     bool delTableRow(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00325     bool setTableRow(const String& name, const String& item, const NamedList* data, Window* wnd = 0, Window* skip = 0);
00326     bool getTableRow(const String& name, const String& item, NamedList* data = 0, Window* wnd = 0, Window* skip = 0);
00327     bool clearTable(const String& name, Window* wnd = 0, Window* skip = 0);
00328     bool getText(const String& name, String& text, Window* wnd = 0, Window* skip = 0);
00329     bool getCheck(const String& name, bool& checked, Window* wnd = 0, Window* skip = 0);
00330     bool getSelect(const String& name, String& item, Window* wnd = 0, Window* skip = 0);
00331     void moveRelated(const Window* wnd, int dx, int dy);
00332     inline bool initialized() const
00333         { return m_initialized; }
00334     inline static Client* self()
00335         { return s_client; }
00336     inline static bool changing()
00337         { return (s_changing > 0); }
00338     inline const String& activeId() const
00339         { return m_activeId; }
00340     static Window* getWindow(const String& name);
00341     static bool setVisible(const String& name, bool show = true);
00342     static bool getVisible(const String& name);
00343     static bool openPopup(const String& name, const NamedList* params = 0, const Window* parent = 0);
00344     static bool openMessage(const char* text, const Window* parent = 0, const char* context = 0);
00345     static bool openConfirm(const char* text, const Window* parent = 0, const char* context = 0);
00346     static ObjList* listWindows();
00347     void idleActions();
00348 protected:
00349     virtual void loadWindows() = 0;
00350     virtual void initWindows();
00351     virtual void initClient();
00352     virtual void setChannelDisplay(ClientChannel* chan);
00353     virtual bool updateCallHist(const NamedList& params);
00354     void addChannel(ClientChannel* chan);
00355     void delChannel(ClientChannel* chan);
00356     void setChannel(ClientChannel* chan);
00357     void setChannelInternal(ClientChannel* chan);
00358     void selectChannel(ClientChannel* chan, bool force = false);
00359     void updateFrom(const String& id);
00360     void updateFrom(const ClientChannel* chan);
00361     void enableAction(const ClientChannel* chan, const String& action);
00362     inline bool needProxy() const
00363         { return m_oneThread && !isCurrent(); }
00364     bool driverLockLoop();
00365     static bool driverLock(long maxwait = 0);
00366     static void driverUnlock();
00367     ObjList m_windows;
00368     String m_activeId;
00369     bool m_initialized;
00370     int m_line;
00371     bool m_oneThread;
00372     bool m_multiLines;
00373     bool m_autoAnswer;
00374     static Client* s_client;
00375     static int s_changing;
00376 };
00377 
00382 class YATE_API ClientChannel : public Channel
00383 {
00384     friend class ClientDriver;
00385 public:
00386     ClientChannel(const String& party, const char* target = 0, const Message* msg = 0);
00387     virtual ~ClientChannel();
00388     virtual bool msgProgress(Message& msg);
00389     virtual bool msgRinging(Message& msg);
00390     virtual bool msgAnswered(Message& msg);
00391     virtual bool callRouted(Message& msg);
00392     virtual void callAccept(Message& msg);
00393     virtual void callRejected(const char* error, const char* reason, const Message* msg);
00394     virtual bool enableAction(const String& action) const;
00395     void callAnswer();
00396     bool openMedia(bool replace = false);
00397     void closeMedia();
00398     inline const String& party() const
00399         { return m_party; }
00400     inline const String& description() const
00401         { return m_desc; }
00402     inline bool flashing() const
00403         { return m_flashing; }
00404     inline void noticed()
00405         { m_flashing = false; }
00406     inline int line() const
00407         { return m_line; }
00408     void line(int newLine);
00409 protected:
00410     void update(bool client = true);
00411     String m_party;
00412     String m_desc;
00413     u_int64_t m_time;
00414     int m_line;
00415     bool m_flashing;
00416     bool m_canAnswer;
00417     bool m_canTransfer;
00418     bool m_canConference;
00419 };
00420 
00425 class YATE_API ClientDriver : public Driver
00426 {
00427 public:
00428     ClientDriver();
00429     virtual ~ClientDriver();
00430     virtual void initialize() = 0;
00431     virtual bool factory(UIFactory* factory, const char* type);
00432     virtual bool msgExecute(Message& msg, String& dest);
00433     virtual void msgTimer(Message& msg);
00434     virtual bool msgRoute(Message& msg);
00435     ClientChannel* findLine(int line);
00436     inline static ClientDriver* self()
00437         { return s_driver; }
00438     inline static const String& device()
00439         { return s_device; }
00440 protected:
00441     void setup();
00442     static ClientDriver* s_driver;
00443     static String s_device;
00444 };
00445 
00446 }; // namespace TelEngine
00447 
00448 #endif /* __YATECBASE_H */
00449 
00450 /* vi: set ts=8 sw=4 sts=4 noet: */

Generated on Fri Jul 7 03:11:37 2006 for Yate by  doxygen 1.4.4