00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00071
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
00210
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 addToLog(const String& text, Window* wnd = 0);
00293 virtual bool setStatus(const String& text, Window* wnd = 0);
00294 bool addToLogLocked(const String& text, Window* wnd = 0);
00295 bool setStatusLocked(const String& text, Window* wnd = 0);
00296 virtual bool action(Window* wnd, const String& name);
00297 virtual bool toggle(Window* wnd, const String& name, bool active);
00298 virtual bool select(Window* wnd, const String& name, const String& item, const String& text = String::empty());
00299 virtual bool callRouting(const String& caller, const String& called, Message* msg = 0);
00300 virtual bool callIncoming(const String& caller, const String& dest = String::empty(), Message* msg = 0);
00301 virtual void updateCDR(const Message& msg);
00302 void clearActive(const String& id);
00303 void callAccept(const char* callId = 0);
00304 void callReject(const char* callId = 0);
00305 void callHangup(const char* callId = 0);
00306 bool callStart(const String& target, const String& line = String::empty(),
00307 const String& proto = String::empty(), const String& account = String::empty());
00308 bool emitDigit(char digit);
00309 inline bool oneThread() const
00310 { return m_oneThread; }
00311 inline int line() const
00312 { return m_line; }
00313 void line(int newLine);
00314 bool hasElement(const String& name, Window* wnd = 0, Window* skip = 0);
00315 bool setActive(const String& name, bool active, Window* wnd = 0, Window* skip = 0);
00316 bool setFocus(const String& name, bool select = false, Window* wnd = 0, Window* skip = 0);
00317 bool setShow(const String& name, bool visible, Window* wnd = 0, Window* skip = 0);
00318 bool setText(const String& name, const String& text, Window* wnd = 0, Window* skip = 0);
00319 bool setCheck(const String& name, bool checked, Window* wnd = 0, Window* skip = 0);
00320 bool setSelect(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00321 bool setUrgent(const String& name, bool urgent, Window* wnd = 0, Window* skip = 0);
00322 bool hasOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00323 bool addOption(const String& name, const String& item, bool atStart, const String& text = String::empty(), Window* wnd = 0, Window* skip = 0);
00324 bool delOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00325 bool addTableRow(const String& name, const String& item, const NamedList* data = 0, bool atStart = false, Window* wnd = 0, Window* skip = 0);
00326 bool delTableRow(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00327 bool setTableRow(const String& name, const String& item, const NamedList* data, Window* wnd = 0, Window* skip = 0);
00328 bool getTableRow(const String& name, const String& item, NamedList* data = 0, Window* wnd = 0, Window* skip = 0);
00329 bool clearTable(const String& name, Window* wnd = 0, Window* skip = 0);
00330 bool getText(const String& name, String& text, Window* wnd = 0, Window* skip = 0);
00331 bool getCheck(const String& name, bool& checked, Window* wnd = 0, Window* skip = 0);
00332 bool getSelect(const String& name, String& item, Window* wnd = 0, Window* skip = 0);
00333 void moveRelated(const Window* wnd, int dx, int dy);
00334 inline bool initialized() const
00335 { return m_initialized; }
00336 inline static Client* self()
00337 { return s_client; }
00338 inline static bool changing()
00339 { return (s_changing > 0); }
00340 inline const String& activeId() const
00341 { return m_activeId; }
00342 static Window* getWindow(const String& name);
00343 static bool setVisible(const String& name, bool show = true);
00344 static bool getVisible(const String& name);
00345 static bool openPopup(const String& name, const NamedList* params = 0, const Window* parent = 0);
00346 static bool openMessage(const char* text, const Window* parent = 0, const char* context = 0);
00347 static bool openConfirm(const char* text, const Window* parent = 0, const char* context = 0);
00348 static ObjList* listWindows();
00349 void idleActions();
00350 protected:
00351 virtual void loadWindows() = 0;
00352 virtual void initWindows();
00353 virtual void initClient();
00354 virtual void exitClient();
00355 virtual void setChannelDisplay(ClientChannel* chan);
00356 virtual bool updateCallHist(const NamedList& params);
00357 void addChannel(ClientChannel* chan);
00358 void delChannel(ClientChannel* chan);
00359 void setChannel(ClientChannel* chan);
00360 void setChannelInternal(ClientChannel* chan);
00361 void selectChannel(ClientChannel* chan, bool force = false);
00362 void updateFrom(const String& id);
00363 void updateFrom(const ClientChannel* chan);
00364 void enableAction(const ClientChannel* chan, const String& action);
00365 inline bool needProxy() const
00366 { return m_oneThread && !isCurrent(); }
00367 bool driverLockLoop();
00368 static bool driverLock(long maxwait = 0);
00369 static void driverUnlock();
00370 ObjList m_windows;
00371 String m_activeId;
00372 bool m_initialized;
00373 int m_line;
00374 bool m_oneThread;
00375 bool m_multiLines;
00376 bool m_autoAnswer;
00377 static Client* s_client;
00378 static int s_changing;
00379 };
00380
00385 class YATE_API ClientChannel : public Channel
00386 {
00387 friend class ClientDriver;
00388 public:
00389 ClientChannel(const String& party, const char* target = 0, const Message* msg = 0);
00390 virtual ~ClientChannel();
00391 virtual bool msgProgress(Message& msg);
00392 virtual bool msgRinging(Message& msg);
00393 virtual bool msgAnswered(Message& msg);
00394 virtual bool callRouted(Message& msg);
00395 virtual void callAccept(Message& msg);
00396 virtual void callRejected(const char* error, const char* reason, const Message* msg);
00397 virtual bool enableAction(const String& action) const;
00398 void callAnswer();
00399 bool openMedia(bool replace = false);
00400 void closeMedia();
00401 inline const String& party() const
00402 { return m_party; }
00403 inline const String& description() const
00404 { return m_desc; }
00405 inline bool flashing() const
00406 { return m_flashing; }
00407 inline void noticed()
00408 { m_flashing = false; }
00409 inline int line() const
00410 { return m_line; }
00411 void line(int newLine);
00412 protected:
00413 virtual void disconnected(bool final, const char* reason);
00414 void update(bool client = true);
00415 String m_party;
00416 String m_desc;
00417 String m_reason;
00418 u_int64_t m_time;
00419 int m_line;
00420 bool m_flashing;
00421 bool m_canAnswer;
00422 bool m_canTransfer;
00423 bool m_canConference;
00424 };
00425
00430 class YATE_API ClientDriver : public Driver
00431 {
00432 public:
00433 ClientDriver();
00434 virtual ~ClientDriver();
00435 virtual void initialize() = 0;
00436 virtual bool factory(UIFactory* factory, const char* type);
00437 virtual bool msgExecute(Message& msg, String& dest);
00438 virtual void msgTimer(Message& msg);
00439 virtual bool msgRoute(Message& msg);
00440 ClientChannel* findLine(int line);
00441 inline static ClientDriver* self()
00442 { return s_driver; }
00443 inline static const String& device()
00444 { return s_device; }
00445 protected:
00446 void setup();
00447 static ClientDriver* s_driver;
00448 static String s_device;
00449 };
00450
00451 };
00452
00453 #endif
00454
00455