Yate
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends

Client Class Reference

Thread that runs the User Interface. More...

#include <yatecbase.h>

Inheritance diagram for Client:
Thread MessageReceiver Runnable GenObject

List of all members.

Public Types

enum  MsgID {
  CallCdr = 0, UiAction = 1, UserLogin = 2, UserNotify = 3,
  ResourceNotify = 4, ResourceSubscribe = 5, ClientChanUpdate = 7, ChanNotify = 8,
  MsgIdCount = 9
}
enum  ClientToggle {
  OptMultiLines = 0, OptAutoAnswer = 1, OptRingIn = 2, OptRingOut = 3,
  OptActivateLastOutCall = 4, OptActivateLastInCall = 5, OptActivateCallOnSelect = 6, OptKeypadVisible = 7,
  OptOpenIncomingUrl = 8, OptCount = 9
}

Public Member Functions

 Client (const char *name=0)
virtual ~Client ()
virtual void run ()
virtual void cleanup ()
virtual void main ()=0
virtual void lock ()=0
virtual void unlock ()=0
void lockOther ()
void unlockOther ()
virtual void allHidden ()=0
void loadUI (const char *file=0, bool init=true)
virtual void quit ()=0
bool openUrlSafe (const String &url)
virtual bool openUrl (const String &url)=0
virtual bool received (Message &msg, int id)
virtual bool createWindowSafe (const String &name, const String &alias=String::empty())
virtual bool createObject (void **dest, const String &type, const char *name, NamedList *params=0)
virtual bool closeWindow (const String &name, bool hide=true)
virtual bool debugHook (bool active)
virtual bool addToLog (const String &text)
virtual bool setStatus (const String &text, Window *wnd=0)
bool setStatusLocked (const String &text, Window *wnd=0)
bool setParams (const NamedList *params, Window *wnd=0, Window *skip=0)
virtual bool action (Window *wnd, const String &name, NamedList *params=0)
virtual bool toggle (Window *wnd, const String &name, bool active)
virtual bool select (Window *wnd, const String &name, const String &item, const String &text=String::empty())
bool oneThread () const
int line () const
void line (int newLine)
bool hasElement (const String &name, Window *wnd=0, Window *skip=0)
bool setActive (const String &name, bool active, Window *wnd=0, Window *skip=0)
bool setFocus (const String &name, bool select=false, Window *wnd=0, Window *skip=0)
bool setShow (const String &name, bool visible, Window *wnd=0, Window *skip=0)
bool setText (const String &name, const String &text, bool richText=false, Window *wnd=0, Window *skip=0)
bool setCheck (const String &name, bool checked, Window *wnd=0, Window *skip=0)
bool setSelect (const String &name, const String &item, Window *wnd=0, Window *skip=0)
bool setUrgent (const String &name, bool urgent, Window *wnd=0, Window *skip=0)
bool hasOption (const String &name, const String &item, Window *wnd=0, Window *skip=0)
virtual bool getOptions (const String &name, NamedList *items, Window *wnd=0, Window *skip=0)
bool addOption (const String &name, const String &item, bool atStart, const String &text=String::empty(), Window *wnd=0, Window *skip=0)
bool delOption (const String &name, const String &item, Window *wnd=0, Window *skip=0)
bool addLines (const String &name, const NamedList *lines, unsigned int max, bool atStart=false, Window *wnd=0, Window *skip=0)
bool addTableRow (const String &name, const String &item, const NamedList *data=0, bool atStart=false, Window *wnd=0, Window *skip=0)
bool setMultipleRows (const String &name, const NamedList &data, const String &prefix=String::empty(), Window *wnd=0, Window *skip=0)
bool insertTableRow (const String &name, const String &item, const String &before, const NamedList *data=0, Window *wnd=0, Window *skip=0)
bool delTableRow (const String &name, const String &item, Window *wnd=0, Window *skip=0)
bool setTableRow (const String &name, const String &item, const NamedList *data, Window *wnd=0, Window *skip=0)
bool getTableRow (const String &name, const String &item, NamedList *data=0, Window *wnd=0, Window *skip=0)
bool clearTable (const String &name, Window *wnd=0, Window *skip=0)
bool updateTableRow (const String &name, const String &item, const NamedList *data=0, bool atStart=false, Window *wnd=0, Window *skip=0)
bool updateTableRows (const String &name, const NamedList *data, bool atStart=false, Window *wnd=0, Window *skip=0)
bool getText (const String &name, String &text, bool richText=false, Window *wnd=0, Window *skip=0)
bool getCheck (const String &name, bool &checked, Window *wnd=0, Window *skip=0)
bool getSelect (const String &name, String &item, Window *wnd=0, Window *skip=0)
virtual bool setProperty (const String &name, const String &item, const String &value, Window *wnd=0, Window *skip=0)
virtual bool getProperty (const String &name, const String &item, String &value, Window *wnd=0, Window *skip=0)
void moveRelated (const Window *wnd, int dx, int dy)
bool initialized () const
void idleActions ()
bool postpone (const Message &msg, int id, bool copyUserData=false)
virtual bool chooseFile (Window *parent, NamedList &params)
virtual bool setClientParam (const String &param, const String &value, bool save, bool update)
virtual bool backspace (const String &name, Window *wnd=0)
void installRelay (const char *name, int id, int prio)
virtual bool callRouting (Message &msg)
virtual bool imRouting (Message &msg)
virtual bool imExecute (Message &msg)
virtual bool buildIncomingChannel (Message &msg, const String &dest)
virtual bool buildOutgoingChannel (NamedList &params)
bool callIncoming (Message &msg, const String &dest)
void callAnswer (const String &id, bool setActive=true)
void callTerminate (const String &id, const char *reason=0, const char *error=0)
ClientChannelgetActiveChannel ()
virtual bool ringer (bool in, bool on)
virtual bool createSound (const char *name, const char *file, const char *device=0)
bool emitDigits (const char *digits, const String &id=String::empty())
bool emitDigit (char digit, const String &id=String::empty())
bool getBoolOpt (ClientToggle toggle)
bool setBoolOpt (ClientToggle toggle, bool value, bool updateUi=false)
virtual bool formatDateTime (String &dest, unsigned int secs, const char *format, bool utc=false)
virtual void engineStart (Message &msg)

Static Public Member Functions

static Clientself ()
static bool valid ()
static bool changing ()
static WindowgetWindow (const String &name)
static bool setVisible (const String &name, bool show=true)
static bool getVisible (const String &name)
static bool openPopup (const String &name, const NamedList *params=0, const Window *parent=0)
static bool openMessage (const char *text, const Window *parent=0, const char *context=0)
static bool openConfirm (const char *text, const Window *parent=0, const char *context=0)
static ObjListlistWindows ()
static bool exiting ()
static bool addLogic (ClientLogic *logic)
static void removeLogic (ClientLogic *logic)
static ClientLogicfindLogic (const String &name)
static MessageeventMessage (const String &event, Window *wnd=0, const char *name=0, NamedList *params=0)
static bool save (Configuration &cfg, Window *parent=0, bool showErr=true)
static ClientToggle getBoolOpt (const String &name)
static void setLogicsTick ()

Static Public Attributes

static Configuration s_settings
static Configuration s_actions
static Configuration s_accounts
static Configuration s_contacts
static Configuration s_providers
static Configuration s_history
static Configuration s_calltoHistory
static Regexp s_notSelected
static String s_skinPath
static String s_soundPath
static String s_ringInName
static String s_ringOutName
static String s_statusWidget
static String s_debugWidget
static String s_toggles [OptCount]

Protected Member Functions

virtual ClientLogiccreateDefaultLogic ()
virtual bool createWindow (const String &name, const String &alias=String::empty())=0
virtual void loadWindows (const char *file=0)=0
virtual void initWindows ()
virtual void initClient ()
virtual void exitClient ()
bool needProxy () const
bool driverLockLoop ()

Static Protected Member Functions

static bool driverLock (long maxwait=0)
static void driverUnlock ()

Protected Attributes

ObjList m_windows
bool m_initialized
int m_line
bool m_oneThread
bool m_toggles [OptCount]
ObjList m_relays
ClientLogicm_defaultLogic

Static Protected Attributes

static bool s_exiting
static Clients_client
static int s_changing
static ObjList s_logics
static bool s_idleLogicsTick

Friends

class Window
class ClientChannel
class ClientDriver
class ClientLogic

Detailed Description

Thread that runs the User Interface.

Singleton class that holds the User Interface's main thread and methods


Member Enumeration Documentation

Client boolean options mapped to UI toggles

enum MsgID

Message relays installed by this receiver.


Constructor & Destructor Documentation

Client ( const char *  name = 0)

Constructor

Parameters:
nameThe client's name
virtual ~Client ( ) [virtual]

Destructor


Member Function Documentation

virtual bool action ( Window wnd,
const String name,
NamedList params = 0 
) [virtual]

Handle actions from user interface. Enqueue an ui.event message if the action is not handled by a client logic

Parameters:
wndThe window in which the user did something
nameThe action's name
paramsOptional action parameters
Returns:
True if the action was handled by a client logic
bool addLines ( const String name,
const NamedList lines,
unsigned int  max,
bool  atStart = false,
Window wnd = 0,
Window skip = 0 
)

Append or insert text lines to a widget

Parameters:
nameThe name of the widget
linesList containing the lines
maxThe maximum number of lines allowed to be displayed. Set to 0 to ignore
atStartTrue to insert, false to append
wndOptional window owning the widget
skipOptional window to skip if wnd is 0
Returns:
True on success
static bool addLogic ( ClientLogic logic) [static]

Add a logic to the list. The added object is not owned by the client

Parameters:
logicPointer to the logic to add
Returns:
True on success. False if the pointer is 0 or already added
virtual bool addToLog ( const String text) [virtual]

Add a log line

Parameters:
textText to add
Returns:
True on success
virtual void allHidden ( ) [pure virtual]

Handle all windows closed event from UI

virtual bool backspace ( const String name,
Window wnd = 0 
) [virtual]

Remove the last character of the given widget

Parameters:
nameThe widget (it might be the window itself)
wndOptional window containing the widget that triggered the action
Returns:
True on success
virtual bool buildIncomingChannel ( Message msg,
const String dest 
) [virtual]

Build an incoming channel. Answer it if succesfully connected and auto answer is set. Reject it if multiline is false and the driver is busy. Set the active one if requested by config and there is no active channel. Start the ringer if there is no active channel

Parameters:
msgThe call.execute message
destThe destination (target)
Returns:
True if a channel was created and connected
virtual bool buildOutgoingChannel ( NamedList params) [virtual]

Build an outgoing channel

Parameters:
paramsCall parameters
Returns:
True if a channel was created its router started
void callAnswer ( const String id,
bool  setActive = true 
)

Answer an incoming call

Parameters:
idThe accepted channel's id
setActiveTrue to activate the answered channel
Returns:
True on success
bool callIncoming ( Message msg,
const String dest 
)

Call execute handler called by the driver. Ask the logics to create the channel

Parameters:
msgThe call.execute message
destThe destination (target)
Returns:
True if a channel was created and connected
virtual bool callRouting ( Message msg) [inline, virtual]

Call routing handler called by the driver

Parameters:
msgThe call.route message
void callTerminate ( const String id,
const char *  reason = 0,
const char *  error = 0 
)

Terminate a call

Parameters:
idThe channel's id
reasonOptional termination reason
errorOptional termination error
Returns:
True on success
virtual bool chooseFile ( Window parent,
NamedList params 
) [inline, virtual]

Show a file open/save dialog window This method isn't using the proxy thread since it's usually called on UI action

Parameters:
parentDialog window's parent
paramsDialog window's params. Parameters that can be specified include 'caption', 'dir', 'filters', 'selectedfilter', 'confirmoverwrite', 'choosedir'.
Returns:
True on success
virtual void cleanup ( ) [virtual]

Cleanup when thread terminates

Reimplemented from Thread.

virtual bool closeWindow ( const String name,
bool  hide = true 
) [virtual]

Hide/destroy a window with a given name

Parameters:
nameThe window's name
hideTrue to hide, false to close
Returns:
True on success
virtual ClientLogic* createDefaultLogic ( ) [protected, virtual]

Create the default logic The default implementation creates a DefaultLogic object

Returns:
ClientLogic pointer or 0
virtual bool createObject ( void **  dest,
const String type,
const char *  name,
NamedList params = 0 
) [virtual]

Ask to an UI factory to create an object in the UI's thread

Parameters:
destDestination to be filled with the newly create object's address
typeObject's type
nameObject's name
paramsOptional object parameters
Returns:
True on success
virtual bool createSound ( const char *  name,
const char *  file,
const char *  device = 0 
) [inline, virtual]

Create a sound object. Append it to the global list

Parameters:
nameThe name of sound object
fileThe file to play (should contain the whole path and the file name)
deviceOptional device used to play the file. Set to 0 to use the default one
Returns:
True on success, false if a sound with the given name already exists
virtual bool createWindowSafe ( const String name,
const String alias = String::empty() 
) [virtual]

Create a window with a given name

Parameters:
nameThe window's name
aliasWindow name alias after succesfully loaded. Set to empty string to use the given name
Returns:
True on success
virtual bool debugHook ( bool  active) [virtual]

Install/uninstall a debugger output hook

Parameters:
activeTrue to install, false to uninstall the hook
Returns:
True on success
bool emitDigit ( char  digit,
const String id = String::empty() 
) [inline]

Send a digit on selected channel

Parameters:
digitThe digit to send
idThe channel id. Use the active one if empty
Returns:
True on success
bool emitDigits ( const char *  digits,
const String id = String::empty() 
)

Send digits on selected channel

Parameters:
digitsThe digits to send
idThe channel id. Use the active one if empty
Returns:
True on success
virtual void engineStart ( Message msg) [virtual]

Engine start notification. Notify all registered logics

Parameters:
msgThe engine.start message
static Message* eventMessage ( const String event,
Window wnd = 0,
const char *  name = 0,
NamedList params = 0 
) [static]

Build an 'ui.event' message

Parameters:
eventEvent's name
wndOptional window to add to message
nameOptional 'name' parameter value
paramsOther optional parameters to be added to the message
Returns:
Valid Message pointer
static bool exiting ( ) [inline, static]

Check if the client is exiting

Returns:
True if the client therad is exiting
static ClientLogic* findLogic ( const String name) [static]

Convenience method to retrieve a logic

Parameters:
nameThe logic's name
Returns:
ClientLogic pointer or 0
virtual bool formatDateTime ( String dest,
unsigned int  secs,
const char *  format,
bool  utc = false 
) [inline, virtual]

Build a date/time string from UTC time

Parameters:
destDestination string
secsSeconds since EPOCH
formatFormat string used to build the destination
utcTrue to build UTC time instead of local time
Returns:
True on success
ClientChannel* getActiveChannel ( )

Get the active channel if any

Returns:
Referenced pointer to the active channel or 0
bool getBoolOpt ( ClientToggle  toggle) [inline]

Get a boolean option of this client

Parameters:
toggleOptions's id to retrieve
Returns:
True on success
static ClientToggle getBoolOpt ( const String name) [static]

Check if a string names a client's boolean option

Parameters:
nameString to check
Returns:
Valid client option index or OptCount if not found
virtual bool getOptions ( const String name,
NamedList items,
Window wnd = 0,
Window skip = 0 
) [virtual]

Get an element's items

Parameters:
nameName of the element to search for
itemsList to fill with element's items
wndOptional window owning the element
skipOptional window to skip when searching for the element
Returns:
True if the element exists
virtual bool getProperty ( const String name,
const String item,
String value,
Window wnd = 0,
Window skip = 0 
) [virtual]

Get a property

Parameters:
nameName of the element
itemProperty's name
valueProperty's value
wndOptional target window
skipOptional window to skip if wnd is 0
Returns:
True on success
bool getText ( const String name,
String text,
bool  richText = false,
Window wnd = 0,
Window skip = 0 
)

Get an element's text

Parameters:
nameName of the element
textThe destination string
richTextTrue to get the element's roch text if supported.
wndOptional window owning the element
skipOptional window to skip if wnd is 0
Returns:
True if the operation was successfull
virtual bool imExecute ( Message msg) [virtual]

Process an IM message

Parameters:
msgThe im.execute of chan.text message
virtual bool imRouting ( Message msg) [inline, virtual]

IM message routing handler called by the driver

Parameters:
msgThe im.route message
bool insertTableRow ( const String name,
const String item,
const String before,
const NamedList data = 0,
Window wnd = 0,
Window skip = 0 
)

Insert a row into a table owned by this window

Parameters:
nameName of the element
itemName of the item to insert
beforeName of the item to insert before
dataTable's columns to set
wndOptional window owning the element
skipOptional window to skip if wnd is 0
Returns:
True if the operation was successfull
void installRelay ( const char *  name,
int  id,
int  prio 
)

Create and install a message relay owned by this client. The new relay will be unistalled when the client is terminated

Parameters:
nameMessage name
idRelay id
prioMessage priority
int line ( ) const [inline]

Get the currently selected line

Returns:
The selected line
void line ( int  newLine)

Set the selected line

Parameters:
newLineThe selected line
void loadUI ( const char *  file = 0,
bool  init = true 
)

Load windows and optionally (re)initialize the client's options.

Parameters:
fileThe resource file describing the windows. Set to 0 to use the default one
initTrue to (re)initialize the client
virtual void lock ( ) [pure virtual]

Lock the client

void lockOther ( ) [inline]

Lock the client only if we are using more then 1 thread

virtual void main ( ) [pure virtual]

Execute the client

bool oneThread ( ) const [inline]

Check if the client is using more then 1 thread

Returns:
True if the client is using more then 1 thread
virtual bool openUrl ( const String url) [pure virtual]

Open an URL (link)

Parameters:
urlThe URL to open
Returns:
True on success
bool openUrlSafe ( const String url)

Open an URL (link) in the client's thread

Parameters:
urlThe URL to open
Returns:
True on success
bool postpone ( const Message msg,
int  id,
bool  copyUserData = false 
)

Postpone a copy of a message to be dispatched from the UI thread

Parameters:
msgMessage to be postponed
idIdentifier of the message to be used on dispatch
copyUserDataCopy source user data in postponed message
Returns:
True if the UI thread was not current so the message was postponed
virtual void quit ( ) [pure virtual]

Terminate application

virtual bool received ( Message msg,
int  id 
) [virtual]

Process a received message. Check for a logic to process it

Parameters:
msgReceived message
idMessage id
Returns:
True if a logic processed the message (stop dispatching it)

Implements MessageReceiver.

static void removeLogic ( ClientLogic logic) [static]

Remove a logic from the list without destroying it

Parameters:
logicPointer to the logic to remove
virtual bool ringer ( bool  in,
bool  on 
) [virtual]

Start/stop ringer. The ringer is started only if not disabled

Parameters:
inTrue if the request is for the incoming call alert, false if it is for the outgoing call ringing alert
onTrue to start, false to stop the sound
Returns:
True on success
virtual void run ( ) [virtual]

Run the client's thread

Implements Runnable.

static bool save ( Configuration cfg,
Window parent = 0,
bool  showErr = true 
) [static]

Save a configuration file. Call openMessage() on failure

Parameters:
cfgThe configuration file to save
parentThe parent of the error window if needded
showErrTrue to open a message popup on failure
Returns:
True on success
virtual bool select ( Window wnd,
const String name,
const String item,
const String text = String::empty() 
) [virtual]

Handle 'select' actions from user interface. Enqueue an ui.event message if the action is not handled by a client logic

Parameters:
wndThe window in which the user selected the object
nameThe action's name
itemItem identifying the selection
textSelection's text
Returns:
True if the action was handled by a client logic
bool setBoolOpt ( ClientToggle  toggle,
bool  value,
bool  updateUi = false 
)

Set a boolean option of this client

Parameters:
toggleOptions's id to set
valueValue to set
updateUiTrue to update UI
Returns:
True if the option's value changed
virtual bool setClientParam ( const String param,
const String value,
bool  save,
bool  update 
) [virtual]

Request to a logic to set a client's parameter. Save the settings file and/or update interface

Parameters:
paramParameter's name
valueThe value of the parameter
saveTrue to save the configuration file
updateTrue to update the interface
Returns:
True on success, false if the parameter doesn't exist, the value is incorrect or failed to save the file
static void setLogicsTick ( ) [inline, static]

Set the flag indicating that the client should tick the logics

bool setMultipleRows ( const String name,
const NamedList data,
const String prefix = String::empty(),
Window wnd = 0,
Window skip = 0 
)

Append or update several table rows at once

Parameters:
nameName of the element
dataParameters to initialize the rows with
prefixPrefix to match (and remove) in parameter names
wndOptional window owning the element
skipOptional window to skip if wnd is 0
Returns:
True if all the operations were successfull
bool setParams ( const NamedList params,
Window wnd = 0,
Window skip = 0 
)

Set multiple window parameters

Parameters:
paramsThe parameter list
wndOptional window whose params are to be set
skipOptional window to skip if wnd is 0
Returns:
True on success
virtual bool setProperty ( const String name,
const String item,
const String value,
Window wnd = 0,
Window skip = 0 
) [virtual]

Set a property

Parameters:
nameName of the element
itemProperty's name
valueProperty's value
wndOptional target window
skipOptional window to skip if wnd is 0
Returns:
True on success
virtual bool setStatus ( const String text,
Window wnd = 0 
) [virtual]

Set the status text

Parameters:
textStatus text
wndOptional window owning the status control
Returns:
True on success
bool setStatusLocked ( const String text,
Window wnd = 0 
)

Set the status text safely

Parameters:
textStatus text
wndOptional window owning the status control
Returns:
True on success
virtual bool toggle ( Window wnd,
const String name,
bool  active 
) [virtual]

Handle actions from checkable widgets. Enqueue an ui.event message if the action is not handled by a client logic

Parameters:
wndThe window in which the user did something
nameThe object's name
activeObject's state
Returns:
True if the action was handled by a client logic
virtual void unlock ( ) [pure virtual]

Unlock the client

void unlockOther ( ) [inline]

Unlock the client only if we are using more then 1 thread

bool updateTableRow ( const String name,
const String item,
const NamedList data = 0,
bool  atStart = false,
Window wnd = 0,
Window skip = 0 
)

Set a table row or add a new one if not found

Parameters:
nameName of the element
itemTable item to set/add
dataOptional list of parameters used to set row data
atStartTrue to add item at start, false to add them to the end
wndOptional window owning the element
skipOptional window to skip if wnd is 0
Returns:
True if the operation was successfull
bool updateTableRows ( const String name,
const NamedList data,
bool  atStart = false,
Window wnd = 0,
Window skip = 0 
)

Add or set one or more table row(s). Screen update is locked while changing the table. Each data list element is a NamedPointer carrying a NamedList with item parameters. The name of an element is the item to update. Set element's value to boolean value 'true' to add a new item if not found or 'false' to set an existing one. Set it to empty string to delete the item

Parameters:
nameName of the table
dataThe list of items to add/set/delete
atStartTrue to add new items at start, false to add them to the end
wndOptional window owning the element
skipOptional window to skip if wnd is 0
Returns:
True if the operation was successfull
static bool valid ( ) [inline, static]

Check if the client object still exists and the client or engine is not exiting

Returns:
True if the client is valid (running) or the method is called from client's thread

References Thread::current(), and Engine::exiting().


The documentation for this class was generated from the following file: