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 Window;
00040 class UIWidget;
00041 class UIFactory;
00042 class Client;
00043 class ClientChannel;
00044 class ClientDriver;
00045 class ClientLogic;
00046 class ClientAccount;
00047 class ClientAccountList;
00048 class ClientContact;
00049 class ClientResource;
00050 class DurationUpdate;
00051 class ClientSound;
00052
00053
00059 class YATE_API Window : public GenObject
00060 {
00061 friend class Client;
00062 public:
00067 Window(const char* id = 0);
00068
00072 virtual ~Window();
00073
00078 virtual const String& toString() const;
00079
00080
00081
00082
00083
00084 virtual void title(const String& text);
00085
00090 virtual void context(const String& text);
00091
00097 virtual bool setParams(const NamedList& params);
00098
00103 virtual void setOver(const Window* parent) = 0;
00104
00110 virtual bool hasElement(const String& name) = 0;
00111
00118 virtual bool setActive(const String& name, bool active) = 0;
00119
00126 virtual bool setFocus(const String& name, bool select = false) = 0;
00127
00134 virtual bool setShow(const String& name, bool visible) = 0;
00135
00143 virtual bool setText(const String& name, const String& text,
00144 bool richText = false) = 0;
00145
00152 virtual bool setCheck(const String& name, bool checked) = 0;
00153
00160 virtual bool setSelect(const String& name, const String& item) = 0;
00161
00168 virtual bool setUrgent(const String& name, bool urgent) = 0;
00169
00176 virtual bool hasOption(const String& name, const String& item) = 0;
00177
00186 virtual bool addOption(const String& name, const String& item, bool atStart = false,
00187 const String& text = String::empty()) = 0;
00188
00195 virtual bool getOptions(const String& name, NamedList* items) = 0;
00196
00203 virtual bool delOption(const String& name, const String& item) = 0;
00204
00213 virtual bool addLines(const String& name, const NamedList* lines, unsigned int max,
00214 bool atStart = false);
00215
00224 virtual bool addTableRow(const String& name, const String& item,
00225 const NamedList* data = 0, bool atStart = false);
00226
00233 virtual bool delTableRow(const String& name, const String& item);
00234
00242 virtual bool setTableRow(const String& name, const String& item, const NamedList* data);
00243
00251 virtual bool getTableRow(const String& name, const String& item, NamedList* data = 0);
00252
00258 virtual bool clearTable(const String& name);
00259
00266 virtual bool getText(const String& name, String& text) = 0;
00267
00274 virtual bool getCheck(const String& name, bool& checked) = 0;
00275
00282 virtual bool getSelect(const String& name, String& item) = 0;
00283
00291 virtual bool setProperty(const String& name, const String& item, const String& value)
00292 { return false; }
00293
00301 virtual bool getProperty(const String& name, const String& item, String& value)
00302 { return false; }
00303
00307 inline void populate() {
00308 if (m_populated)
00309 return;
00310 doPopulate();
00311 m_populated = true;
00312 }
00313
00317 inline void init() {
00318 if (m_initialized)
00319 return;
00320 doInit();
00321 m_initialized = true;
00322 }
00323
00327 virtual void show() = 0;
00328
00332 virtual void hide() = 0;
00333
00339 virtual void size(int width, int height) = 0;
00340
00346 virtual void move(int x, int y) = 0;
00347
00353 virtual void moveRel(int dx, int dy) = 0;
00354
00360 virtual bool related(const Window* wnd) const;
00361
00362 virtual void menu(int x, int y) = 0;
00363
00368 virtual bool canClose()
00369 { return true; }
00370
00375 inline const String& id() const
00376 { return m_id; }
00377
00378
00379
00380
00381
00382 inline const String& title() const
00383 { return m_title; }
00384
00389 inline const String& context() const
00390 { return m_context; }
00391
00396 inline bool visible() const
00397 { return m_visible; }
00398
00403 inline void visible(bool yes)
00404 { if (yes) show(); else hide(); }
00405
00410 inline bool master() const
00411 { return m_master; }
00412
00417 inline bool popup() const
00418 { return m_popup; }
00419
00426 static bool isValidParamPrefix(const String& prefix);
00427
00428 protected:
00429 virtual void doPopulate() = 0;
00430 virtual void doInit() = 0;
00431
00432 String m_id;
00433 String m_title;
00434 String m_context;
00435 bool m_visible;
00436 bool m_master;
00437 bool m_popup;
00438 bool m_saveOnClose;
00439
00440 private:
00441 bool m_populated;
00442 bool m_initialized;
00443 };
00444
00445 class YATE_API UIWidget : public String
00446 {
00447 public:
00452 inline UIWidget(const char* name = 0)
00453 : String(name)
00454 {}
00455
00459 virtual ~UIWidget()
00460 {}
00461
00466 inline const String& name() const
00467 { return toString(); }
00468
00474 virtual bool setParams(const NamedList& params)
00475 { return false; }
00476
00482 virtual bool getOptions(NamedList& items)
00483 { return false; }
00484
00492 virtual bool addTableRow(const String& item, const NamedList* data = 0,
00493 bool atStart = false)
00494 { return false; }
00495
00501 virtual bool delTableRow(const String& item)
00502 { return false; }
00503
00510 virtual bool setTableRow(const String& item, const NamedList* data)
00511 { return false; }
00512
00519 virtual bool getTableRow(const String& item, NamedList* data = 0)
00520 { return false; }
00521
00526 virtual bool clearTable()
00527 { return false; }
00528
00534 virtual bool getSelect(String& item)
00535 { return false; }
00536 };
00537
00543 class YATE_API UIFactory : public String
00544 {
00545 public:
00549 UIFactory(const char* name);
00550
00554 virtual ~UIFactory();
00555
00561 inline bool canBuild(const String& type)
00562 { return 0 != m_types.find(type); }
00563
00571 virtual void* create(const String& type, const char* name, NamedList* params = 0) = 0;
00572
00582 static void* build(const String& type, const char* name, NamedList* params = 0,
00583 const char* factory = 0);
00584
00585 protected:
00586 ObjList m_types;
00587
00588 private:
00589 static ObjList s_factories;
00590 };
00591
00596 class YATE_API Client : public Thread, public MessageReceiver
00597 {
00598 friend class Window;
00599 friend class ClientChannel;
00600 friend class ClientDriver;
00601 friend class ClientLogic;
00602 public:
00606 enum MsgID {
00607 CallCdr = 0,
00608 UiAction = 1,
00609 UserLogin = 2,
00610 UserNotify = 3,
00611 ResourceNotify = 4,
00612 ResourceSubscribe = 5,
00613 XmppIq = 7,
00614 ClientChanUpdate = 8,
00615
00616 ChanNotify = 9,
00617
00618
00619 MsgIdCount = 10
00620 };
00621
00625 enum ClientToggle {
00626 OptMultiLines = 0,
00627 OptAutoAnswer = 1,
00628 OptRingIn = 2,
00629 OptRingOut = 3,
00630 OptActivateLastOutCall = 4,
00631 OptActivateLastInCall = 5,
00632 OptActivateCallOnSelect = 6,
00633 OptKeypadVisible = 7,
00634 OptCount = 8
00635 };
00636
00640 enum Protocol {
00641 SIP = 0,
00642 JABBER = 1,
00643 H323 = 2,
00644 IAX = 3,
00645 OtherProtocol = 4
00646 };
00647
00652 Client(const char *name = 0);
00653
00657 virtual ~Client();
00658
00662 virtual void run();
00663
00667 virtual void cleanup();
00668
00672 virtual void main() = 0;
00673
00677 virtual void lock() = 0;
00678
00682 virtual void unlock() = 0;
00683
00687 inline void lockOther()
00688 { if (!m_oneThread) lock(); }
00689
00693 inline void unlockOther()
00694 { if (!m_oneThread) unlock(); }
00695
00699 virtual void allHidden() = 0;
00700
00706 void loadUI(const char* file = 0, bool init = true);
00707
00711 virtual void quit() = 0;
00712
00719 virtual bool received(Message& msg, int id);
00720
00728 virtual bool createWindowSafe(const String& name,
00729 const String& alias = String::empty());
00730
00739 virtual bool createObject(void** dest, const String& type, const char* name,
00740 NamedList* params = 0);
00741
00748 virtual bool closeWindow(const String& name, bool hide = true);
00749
00755 virtual bool debugHook(bool active);
00756
00762 virtual bool addToLog(const String& text);
00763
00770 virtual bool setStatus(const String& text, Window* wnd = 0);
00771
00778 bool setStatusLocked(const String& text, Window* wnd = 0);
00779
00787 bool setParams(const NamedList* params, Window* wnd = 0, Window* skip = 0);
00788
00797 virtual bool action(Window* wnd, const String& name, NamedList* params = 0);
00798
00807 virtual bool toggle(Window* wnd, const String& name, bool active);
00808
00818 virtual bool select(Window* wnd, const String& name, const String& item, const String& text = String::empty());
00819
00824 inline bool oneThread() const
00825 { return m_oneThread; }
00826
00831 inline int line() const
00832 { return m_line; }
00833
00838 void line(int newLine);
00839
00840 bool hasElement(const String& name, Window* wnd = 0, Window* skip = 0);
00841 bool setActive(const String& name, bool active, Window* wnd = 0, Window* skip = 0);
00842 bool setFocus(const String& name, bool select = false, Window* wnd = 0, Window* skip = 0);
00843 bool setShow(const String& name, bool visible, Window* wnd = 0, Window* skip = 0);
00844 bool setText(const String& name, const String& text, bool richText = false,
00845 Window* wnd = 0, Window* skip = 0);
00846 bool setCheck(const String& name, bool checked, Window* wnd = 0, Window* skip = 0);
00847 bool setSelect(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00848 bool setUrgent(const String& name, bool urgent, Window* wnd = 0, Window* skip = 0);
00849 bool hasOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00850
00859 virtual bool getOptions(const String& name, NamedList* items,
00860 Window* wnd = 0, Window* skip = 0);
00861
00862 bool addOption(const String& name, const String& item, bool atStart,
00863 const String& text = String::empty(), Window* wnd = 0, Window* skip = 0);
00864 bool delOption(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00865
00876 virtual bool addLines(const String& name, const NamedList* lines, unsigned int max,
00877 bool atStart = false, Window* wnd = 0, Window* skip = 0);
00878
00879 bool addTableRow(const String& name, const String& item, const NamedList* data = 0,
00880 bool atStart = false, Window* wnd = 0, Window* skip = 0);
00881 bool delTableRow(const String& name, const String& item, Window* wnd = 0, Window* skip = 0);
00882 bool setTableRow(const String& name, const String& item, const NamedList* data,
00883 Window* wnd = 0, Window* skip = 0);
00884 bool getTableRow(const String& name, const String& item, NamedList* data = 0,
00885 Window* wnd = 0, Window* skip = 0);
00886 bool clearTable(const String& name, Window* wnd = 0, Window* skip = 0);
00887 bool getText(const String& name, String& text, Window* wnd = 0, Window* skip = 0);
00888 bool getCheck(const String& name, bool& checked, Window* wnd = 0, Window* skip = 0);
00889 bool getSelect(const String& name, String& item, Window* wnd = 0, Window* skip = 0);
00890
00900 virtual bool setProperty(const String& name, const String& item, const String& value,
00901 Window* wnd = 0, Window* skip = 0);
00902
00912 virtual bool getProperty(const String& name, const String& item, String& value,
00913 Window* wnd = 0, Window* skip = 0);
00914
00915 void moveRelated(const Window* wnd, int dx, int dy);
00916 inline bool initialized() const
00917 { return m_initialized; }
00918 inline static Client* self()
00919 { return s_client; }
00920 inline static bool changing()
00921 { return (s_changing > 0); }
00922 static Window* getWindow(const String& name);
00923 static bool setVisible(const String& name, bool show = true);
00924 static bool getVisible(const String& name);
00925 static bool openPopup(const String& name, const NamedList* params = 0, const Window* parent = 0);
00926 static bool openMessage(const char* text, const Window* parent = 0, const char* context = 0);
00927 static bool openConfirm(const char* text, const Window* parent = 0, const char* context = 0);
00928 static ObjList* listWindows();
00929 void idleActions();
00930
00942 virtual bool chooseFile(Window* parent, const NamedList& params,
00943 NamedList* files, String* file)
00944 { return false; }
00945
00956 virtual bool setClientParam(const String& param, const String& value,
00957 bool save, bool update);
00958
00965 virtual bool backspace(const String& name, Window* wnd = 0);
00966
00974 void installRelay(const char* name, int id, int prio);
00975
00980 virtual bool callRouting(Message& msg)
00981 { return true;}
00982
00993 virtual bool buildIncomingChannel(Message& msg, const String& dest);
00994
01000 virtual bool buildOutgoingChannel(NamedList& params);
01001
01009 bool callIncoming(Message& msg, const String& dest);
01010
01016 void callAnswer(const String& id);
01017
01025 void callTerminate(const String& id, const char* reason = 0, const char* error = 0);
01026
01031 ClientChannel* getActiveChannel();
01032
01040 virtual bool ringer(bool in, bool on);
01041
01049 virtual bool createSound(const char* name, const char* file, const char* device = 0)
01050 { return false; }
01051
01058 bool emitDigits(const char* digits, const String& id = String::empty());
01059
01066 inline bool emitDigit(char digit, const String& id = String::empty()) {
01067 char s[2] = {digit,0};
01068 return emitDigits(s,id);
01069 }
01070
01076 inline bool getBoolOpt(ClientToggle toggle)
01077 { return toggle < OptCount ? m_toggles[toggle] : false; }
01078
01086 bool setBoolOpt(ClientToggle toggle, bool value, bool updateUi = false);
01087
01093 static bool addLogic(ClientLogic* logic);
01094
01099 static void removeLogic(ClientLogic* logic);
01100
01106 static ClientLogic* findLogic(const String& name);
01107
01116 static Message* eventMessage(const String& event, Window* wnd = 0,
01117 const char* name = 0, NamedList* params = 0);
01118
01126 static bool save(Configuration& cfg, Window* parent = 0, bool showErr = true);
01127
01133 static ClientToggle getBoolOpt(const String& name);
01134
01138 static inline void setLogicsTick()
01139 { s_idleLogicsTick = true; }
01140
01144 static inline Protocol getProtocol(const String& proto) {
01145 for (int i = 0; i < OtherProtocol; i++)
01146 if (proto == s_protocols[i])
01147 return (Protocol)i;
01148 return OtherProtocol;
01149 }
01150
01154 static inline const String& getProtocol(int proto)
01155 { return proto < OtherProtocol ? s_protocols[proto] : String::empty(); }
01156
01157 static Configuration s_settings;
01158 static Configuration s_actions;
01159 static Configuration s_accounts;
01160 static Configuration s_contacts;
01161 static Configuration s_providers;
01162 static Configuration s_history;
01163 static Configuration s_calltoHistory;
01164
01165 static Regexp s_notSelected;
01166
01167 static const char* s_provParams[];
01168
01169 static ObjList s_accOptions;
01170
01171 static String s_protocols[OtherProtocol];
01172
01173 static String s_skinPath;
01174 static String s_soundPath;
01175
01176 static String s_ringInName;
01177
01178 static String s_ringOutName;
01179
01180 static String s_statusWidget;
01181
01182 static String s_debugWidget;
01183
01184 static String s_toggles[OptCount];
01185
01186 protected:
01187 virtual bool createWindow(const String& name,
01188 const String& alias = String::empty()) = 0;
01189 virtual void loadWindows(const char* file = 0) = 0;
01190 virtual void initWindows();
01191 virtual void initClient();
01192 virtual void exitClient()
01193 {}
01194 inline bool needProxy() const
01195 { return m_oneThread && !isCurrent(); }
01196 bool driverLockLoop();
01197 static bool driverLock(long maxwait = 0);
01198 static void driverUnlock();
01199
01200 ObjList m_windows;
01201 bool m_initialized;
01202 int m_line;
01203 bool m_oneThread;
01204 bool m_toggles[OptCount];
01205 ObjList m_relays;
01206 static Client* s_client;
01207 static int s_changing;
01208 static ObjList s_logics;
01209 static bool s_idleLogicsTick;
01210 };
01211
01216 class YATE_API ClientChannel : public Channel
01217 {
01218 friend class ClientDriver;
01219 public:
01223 enum Notification {
01224 Startup,
01225 Destroyed,
01226 Active,
01227 OnHold,
01228 Noticed,
01229 AddrChanged,
01230 Routed,
01231 Accepted,
01232 Rejected,
01233 Progressing,
01234 Ringing,
01235 Answered,
01236 Transfer,
01237 Conference,
01238 Unknown
01239 };
01240
01241
01242 ClientChannel(const Message& msg, const String& peerid);
01243
01244 ClientChannel(const String& target, const NamedList& params);
01245 virtual ~ClientChannel();
01246 virtual bool msgProgress(Message& msg);
01247 virtual bool msgRinging(Message& msg);
01248 virtual bool msgAnswered(Message& msg);
01249 virtual bool msgDrop(Message& msg, const char* reason);
01250 virtual bool callRouted(Message& msg);
01251 virtual void callAccept(Message& msg);
01252 virtual void callRejected(const char* error, const char* reason, const Message* msg);
01253
01257 void callAnswer();
01258
01263 inline const String& party() const
01264 { return m_party; }
01265
01270 inline bool conference() const
01271 { return m_conference; }
01272
01277 inline const String& transferId() const
01278 { return m_transferId; }
01279
01284 inline RefObject* clientData() const
01285 { return m_clientData; }
01286
01292 inline void setClientData(RefObject* obj = 0) {
01293 TelEngine::destruct(m_clientData);
01294 if (obj && obj->ref())
01295 m_clientData = obj;
01296 }
01297
01304 bool setMedia(bool open = false, bool replace = false);
01305
01312 bool setActive(bool active, bool update = true);
01313
01319 void setTransfer(const String& target = String::empty());
01320
01326 void setConference(const String& target = String::empty());
01327
01332 inline const String& peerOutFormat() const
01333 { return m_peerOutFormat; }
01334
01339 inline const String& peerInFormat() const
01340 { return m_peerInFormat; }
01341
01346 inline bool active() const
01347 { return m_active; }
01348
01353 inline bool isNoticed() const
01354 { return m_noticed; }
01355
01359 void noticed();
01360
01365 inline int line() const
01366 { return m_line; }
01367
01372 void line(int newLine);
01373
01384 void update(int notif, bool chan = true,
01385 bool updatePeer = true, const char* engineMsg = 0,
01386 bool minimal = false, bool data = false);
01387
01394 static int lookup(const char* notif, int def = Unknown)
01395 { return TelEngine::lookup(notif,s_notification,def); }
01396
01403 static const char* lookup(int notif, const char* def = 0)
01404 { return TelEngine::lookup(notif,s_notification,def); }
01405
01409 static TokenDict s_notification[];
01410
01411 protected:
01412 virtual void destroyed();
01413 virtual void disconnected(bool final, const char* reason);
01414
01415 inline bool peerHasSource(Message& msg) {
01416 CallEndpoint* ch = getPeer();
01417 if (!ch)
01418 ch = static_cast<CallEndpoint*>(msg.userObject("CallEndpoint"));
01419 return ch && ch->getSource();
01420 }
01421
01422
01423 void checkSilence();
01424
01425 String m_party;
01426 String m_peerOutFormat;
01427 String m_peerInFormat;
01428 String m_reason;
01429 String m_peerId;
01430 bool m_noticed;
01431 int m_line;
01432 bool m_active;
01433 bool m_silence;
01434 bool m_conference;
01435 String m_transferId;
01436 RefObject* m_clientData;
01437 };
01438
01443 class YATE_API ClientDriver : public Driver
01444 {
01445 friend class ClientChannel;
01446 public:
01447 ClientDriver();
01448 virtual ~ClientDriver();
01449 virtual void initialize() = 0;
01450 virtual bool msgExecute(Message& msg, String& dest);
01451 virtual void msgTimer(Message& msg);
01452 virtual bool msgRoute(Message& msg);
01453 virtual bool received(Message& msg, int id);
01454
01459 inline const String& activeId() const
01460 { return m_activeId; }
01461
01470 bool setActive(const String& id = String::empty());
01471
01477 ClientChannel* findLine(int line);
01478
01483 inline static ClientDriver* self()
01484 { return s_driver; }
01485
01490 inline static const String& device()
01491 { return s_device; }
01492
01499 static bool setAudioTransfer(const String& id, const String& target = String::empty());
01500
01509 static bool setConference(const String& id, bool in, const String* confName = 0);
01510
01516 static ClientChannel* findChan(const String& id);
01517
01523 static ClientChannel* findChanByPeer(const String& peer);
01524
01529 static ClientChannel* findActiveChan()
01530 { return self() ? findChan(self()->activeId()) : 0; }
01531
01535 static String s_confName;
01536
01541 static bool s_dropConfPeer;
01542
01543 protected:
01544 void setup();
01545 static ClientDriver* s_driver;
01546 static String s_device;
01547 String m_activeId;
01548 };
01549
01556 class YATE_API ClientLogic : public GenObject
01557 {
01558 friend class Client;
01559 public:
01563 ClientLogic();
01564
01570 ClientLogic(const char* name, int priority);
01571
01575 virtual ~ClientLogic();
01576
01581 virtual const String& toString() const;
01582
01587 inline int priority() const
01588 { return m_prio; }
01589
01595 bool setParams(const NamedList& params);
01596
01604 virtual bool action(Window* wnd, const String& name, NamedList* params = 0);
01605
01613 virtual bool toggle(Window* wnd, const String& name, bool active);
01614
01623 virtual bool select(Window* wnd, const String& name, const String& item,
01624 const String& text = String::empty());
01625
01634 virtual bool setClientParam(const String& param, const String& value,
01635 bool save, bool update);
01636
01644 virtual bool callIncoming(Message& msg, const String& dest)
01645 { return Client::self() && Client::self()->buildIncomingChannel(msg,dest); }
01646
01654 virtual bool callStart(NamedList& params, Window* wnd = 0);
01655
01663 virtual bool digitPressed(NamedList& params, Window* wnd = 0);
01664
01671 virtual bool line(const String& name, Window* wnd = 0);
01672
01680 virtual bool display(NamedList& params, bool widget, Window* wnd = 0);
01681
01689 virtual bool backspace(const String& name, Window* wnd = 0);
01690
01698 virtual bool command(const String& name, Window* wnd = 0);
01699
01708 virtual bool debug(const String& name, bool active, Window* wnd = 0);
01709
01717 virtual bool editAccount(bool newAcc, NamedList* params, Window* wnd = 0);
01718
01725 virtual bool acceptAccount(NamedList* params, Window* wnd = 0);
01726
01733 virtual bool delAccount(const String& account, Window* wnd = 0);
01734
01742 virtual bool updateAccount(const NamedList& account, bool login, bool save);
01743
01750 virtual bool loginAccount(const NamedList& account, bool login);
01751
01760 virtual bool updateContact(const NamedList& contact, bool save, bool update);
01761
01768 virtual bool acceptContact(NamedList* params, Window* wnd = 0);
01769
01777 virtual bool editContact(bool newCont, NamedList* params = 0, Window* wnd = 0);
01778
01785 virtual bool delContact(const String& contact, Window* wnd = 0);
01786
01793 virtual bool callContact(NamedList* params = 0, Window* wnd = 0);
01794
01802 virtual bool updateProviders(const NamedList& provider, bool save, bool update);
01803
01811 virtual bool callLogUpdate(NamedList& params, bool save, bool update);
01812
01821 virtual bool callLogClear(const String& table, const String& direction);
01822
01828 virtual bool callLogCall(const String& billid);
01829
01835 virtual bool callLogCreateContact(const String& billid);
01836
01843 virtual bool help(const String& action, Window* wnd);
01844
01849 virtual bool calltoLoaded();
01850
01854 virtual void loadedWindows()
01855 {}
01856
01860 virtual void initializedWindows();
01861
01868 virtual bool initializedClient();
01869
01874 virtual void exitingClient();
01875
01882 virtual bool handleUiAction(Message& msg, bool& stopLogic);
01883
01890 virtual bool handleCallCdr(Message& msg, bool& stopLogic);
01891
01898 virtual bool handleUserLogin(Message& msg, bool& stopLogic);
01899
01906 virtual bool handleUserNotify(Message& msg, bool& stopLogic);
01907
01914 virtual bool handleResourceNotify(Message& msg, bool& stopLogic);
01915
01922 virtual bool handleResourceSubscribe(Message& msg, bool& stopLogic);
01923
01930 virtual bool handleXmppIq(Message& msg, bool& stopLogic)
01931 { return false; }
01932
01939 virtual bool handleClientChanUpdate(Message& msg, bool& stopLogic);
01940
01950 virtual bool defaultMsgHandler(Message& msg, int id, bool& stopLogic);
01951
01957 virtual void updateSelectedChannel(const String* item = 0);
01958
01965 bool addDurationUpdate(DurationUpdate* duration, bool autoDelete = false);
01966
01973 bool removeDurationUpdate(const String& name, bool delObj = false);
01974
01981 bool removeDurationUpdate(DurationUpdate* duration, bool delObj = false);
01982
01989 DurationUpdate* findDurationUpdate(const String& name, bool ref = true);
01990
01994 void clearDurationUpdate();
01995
01996 protected:
02002 virtual void idleTimerTick(Time& time);
02003
02009 virtual bool enableCallActions(const String& id);
02010
02017 virtual bool fillCallStart(NamedList& p, Window* wnd = 0);
02018
02024 virtual void channelSelectionChanged(const String& old);
02025
02026 String m_name;
02027 String m_selectedChannel;
02028 int m_prio;
02029 ObjList m_durationUpdate;
02030 Mutex m_durationMutex;
02031 String m_transferInitiated;
02032 bool m_accShowAdvanced;
02033 };
02034
02041 class YATE_API ClientAccount : public RefObject, public Mutex
02042 {
02043 friend class ClientContact;
02044 public:
02052 ClientAccount(const char* proto, const char* user,
02053 const char* host, bool startup);
02054
02059 ClientAccount(const NamedList& params);
02060
02065 inline const URI& uri() const
02066 { return m_uri; }
02067
02072 inline const URI& id() const
02073 { return m_id; }
02074
02079 inline ObjList& contacts()
02080 { return m_contacts; }
02081
02086 virtual const String& toString() const
02087 { return m_id; }
02088
02093 ClientResource* resource(bool ref = false);
02094
02099 void setResource(ClientResource* res = 0);
02100
02107 virtual ClientContact* findContact(const String& id, bool ref = false);
02108
02116 virtual ClientContact* findContact(const String& id, const String& resid,
02117 bool ref = false);
02118
02125 virtual ClientContact* appendContact(const String& id, const char* name);
02126
02132 virtual ClientContact* appendContact(const NamedList& params);
02133
02140 virtual ClientContact* removeContact(const String& id, bool delObj = true);
02141
02148 virtual Message* userlogin(bool login, const char* msg = "user.login");
02149
02157 static void buildAccountId(URI& dest, const char* proto, const char* user, const char* host) {
02158 URI u(proto,user,host);
02159 dest = u.toLower();
02160 }
02161
02162 String m_password;
02163 String m_server;
02164 int m_port;
02165 String m_options;
02166 bool m_startup;
02167 String m_outbound;
02168 int m_expires;
02169 bool m_connected;
02170
02171 protected:
02172
02173 virtual void destroyed();
02174
02175 virtual void appendContact(ClientContact* contact);
02176
02177 inline void setIdUri(const char* proto, const char* user,
02178 const char* host) {
02179 buildAccountId(m_id,proto,user,host);
02180 m_uri = String(user) + "@" + host;
02181 }
02182
02183 URI m_id;
02184 URI m_uri;
02185 ClientResource* m_resource;
02186 ObjList m_contacts;
02187 };
02188
02193 class YATE_API ClientAccountList : public String, public Mutex
02194 {
02195 public:
02200 inline ClientAccountList(const char* name)
02201 : String(name), Mutex(true)
02202 {}
02203
02208 inline ObjList& accounts()
02209 { return m_accounts; }
02210
02217 virtual ClientAccount* findAccount(const String& id, bool ref = false);
02218
02226 virtual ClientContact* findContact(const String& account, const String& id, bool ref = false);
02227
02234 virtual ClientContact* findContact(const String& builtId, bool ref = false);
02235
02241 virtual bool appendAccount(ClientAccount* account);
02242
02247 virtual void removeAccount(const String& id);
02248
02249 protected:
02250 ObjList m_accounts;
02251 };
02252
02258 class YATE_API ClientContact : public RefObject
02259 {
02260 friend class ClientAccount;
02261 public:
02269 ClientContact(ClientAccount* owner, const char* id, const char* name = 0,
02270 bool chat = false);
02271
02279 ClientContact(ClientAccount* owner, NamedList& params, bool chat);
02280
02285 inline ClientAccount* account()
02286 { return m_owner; }
02287
02292 inline const URI& uri() const
02293 { return m_uri; }
02294
02299 inline ObjList& resources()
02300 { return m_resources; }
02301
02306 inline ObjList& groups()
02307 { return m_groups; }
02308
02313 virtual const String& toString() const
02314 { return m_id; }
02315
02320 inline void buildContactId(String& dest)
02321 { buildContactId(dest,m_owner?m_owner->toString():String::empty(),m_id); }
02322
02328 inline bool isChatWnd(Window* wnd)
02329 { return wnd && wnd->toString() == m_chatWndName; }
02330
02335 inline bool hasChat()
02336 { return Client::self() && Client::self()->getWindow(m_chatWndName); }
02337
02342 inline bool isChatVisible()
02343 { return Client::self() && Client::self()->getVisible(m_chatWndName); }
02344
02350 inline bool showChat(bool active)
02351 { return Client::self() ? Client::self()->setVisible(m_chatWndName,active) : false; }
02352
02358 void createChatWindow(bool force = false, const char* name = "chat");
02359
02363 inline void destroyChatWindow() {
02364 if (m_chatWndName && Client::self())
02365 Client::self()->closeWindow(m_chatWndName,false);
02366 }
02367
02373 virtual String* findGroup(const String& group);
02374
02380 virtual bool appendGroup(const String& group);
02381
02387 virtual bool removeGroup(const String& group);
02388
02395 virtual ClientResource* findResource(const String& id, bool ref = false);
02396
02402 virtual ClientResource* findAudioResource(bool ref = false);
02403
02409 virtual ClientResource* appendResource(const String& id);
02410
02416 virtual bool removeResource(const String& id);
02417
02423 static inline bool isChatWndPrefix(Window* wnd)
02424 { return wnd && wnd->toString().startsWith(s_chatPrefix); }
02425
02432 static inline void buildContactId(String& dest, const String& account,
02433 const String& contact)
02434 { dest << String(account).toLower() << "|" << String(contact).toLower(); }
02435
02442 static inline void splitContactId(const String& src, String& account,
02443 String& contact) {
02444 int pos = src.find('|');
02445 if (pos < 1) {
02446 account = src;
02447 return;
02448 }
02449 account = src.substr(0,pos);
02450 contact = src.substr(pos + 1);
02451 }
02452
02453
02454 static String s_chatPrefix;
02455
02456 String m_name;
02457 String m_subscription;
02458
02459 protected:
02460
02461 virtual void destroyed();
02462
02463 ClientAccount* m_owner;
02464 String m_id;
02465 URI m_uri;
02466 ObjList m_resources;
02467 ObjList m_groups;
02468
02469 private:
02470 String m_chatWndName;
02471 };
02472
02477 class YATE_API ClientResource : public RefObject
02478 {
02479 public:
02486 inline ClientResource(const char* id, const char* name = 0, bool audio = true)
02487 : m_name(name ? name : id), m_audio(audio), m_priority(0), m_id(id)
02488 {}
02489
02494 virtual const String& toString() const
02495 { return m_id; }
02496
02497 String m_name;
02498 bool m_audio;
02499 int m_priority;
02500 String m_status;
02501
02502 protected:
02503 String m_id;
02504 };
02505
02511 class YATE_API DurationUpdate : public RefObject
02512 {
02513 public:
02522 inline DurationUpdate(ClientLogic* logic, bool owner, const char* id,
02523 const char* name, unsigned int start = Time::secNow())
02524 : m_id(id), m_logic(0), m_name(name), m_startTime(start)
02525 { setLogic(logic,owner); }
02526
02530 virtual ~DurationUpdate()
02531 { setLogic(); }
02532
02537 virtual const String& toString() const
02538 { return m_id; }
02539
02545 void setLogic(ClientLogic* logic = 0, bool owner = true);
02546
02556 virtual unsigned int update(unsigned int secNow, const String* table = 0,
02557 Window* wnd = 0, Window* skip = 0, bool force = false);
02558
02566 virtual unsigned int buildTimeParam(NamedList& dest, unsigned int secNow,
02567 bool force = false)
02568 { return buildTimeParam(dest,m_name,m_startTime,secNow,force); }
02569
02577 virtual unsigned int buildTimeString(String& dest, unsigned int secNow,
02578 bool force = false)
02579 { return buildTimeString(dest,m_startTime,secNow,force); }
02580
02590 static unsigned int buildTimeParam(NamedList& dest, const char* param, unsigned int secStart,
02591 unsigned int secNow, bool force = false);
02592
02601 static unsigned int buildTimeString(String& dest, unsigned int secStart, unsigned int secNow,
02602 bool force = false);
02603
02604 protected:
02608 virtual void destroyed() {
02609 setLogic();
02610 RefObject::destroyed();
02611 }
02612
02613 String m_id;
02614 ClientLogic* m_logic;
02615 String m_name;
02616 unsigned int m_startTime;
02617 };
02618
02623 class YATE_API ClientSound : public String
02624 {
02625 public:
02632 inline ClientSound(const char* name, const char* file, const char* device = 0)
02633 : String(name), m_file(file), m_device(device), m_repeat(-1), m_started(false)
02634 {}
02635
02639 virtual ~ClientSound()
02640 { stop(); }
02641
02645 virtual void destruct() {
02646 stop();
02647 String::destruct();
02648 }
02649
02654 inline bool started() const
02655 { return m_started; }
02656
02661 inline const String& file() const
02662 { return m_file; }
02663
02669 inline void file(const char* filename)
02670 { m_file = filename; }
02671
02679 bool start(int repeat = -1, bool force = true);
02680
02684 void stop();
02685
02691 static bool started(const String& name);
02692
02701 static bool start(const String& name, int repeat = -1, bool force = true);
02702
02707 static void stop(const String& name);
02708
02715 static ClientSound* find(const String& token, bool byName = true);
02716
02720 static ObjList s_sounds;
02721
02725 static Mutex s_soundsMutex;
02726
02727 protected:
02728 virtual bool doStart()
02729 { return false; }
02730 virtual void doStop()
02731 {}
02732
02733 String m_file;
02734 String m_device;
02735 int m_repeat;
02736 bool m_started;
02737 };
02738
02739 };
02740
02741 #endif
02742
02743