Added utilities used to build messages sent by the client.

git-svn-id: http://voip.null.ro/svn/yate@3208 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
marian 2010-04-19 12:01:21 +00:00
parent b39e7a2455
commit c48ee2974d
2 changed files with 115 additions and 1 deletions

View File

@ -908,6 +908,14 @@ void Client::run()
exitClient();
}
// Check if a message is sent by the client
bool Client::isClientMsg(Message& msg)
{
String* module = msg.getParam("module");
return module && ClientDriver::self() &&
ClientDriver::self()->name() == *module;
}
// retrieve the window named by the value of "name" from the client's list of windows
Window* Client::getWindow(const String& name)
{
@ -2158,6 +2166,8 @@ bool Client::imExecute(Message& msg)
{
static String sect = "miscellaneous";
if (Client::isClientMsg(msg))
return false;
XDebug(ClientDriver::self(),DebugAll,"Client::imExecute [%p]",this);
// Check for a preferred or only logic
String name = "imincoming";
@ -2414,6 +2424,58 @@ void Client::engineStart(Message& msg)
}
}
// Build a message to be sent by the client.
Message* Client::buildMessage(const char* msg, const String& account, const char* oper)
{
Message* m = new Message(msg);
if (ClientDriver::self())
m->addParam("module",ClientDriver::self()->name());
if (!TelEngine::null(oper))
m->addParam("operation",oper);
m->addParam("account",account);
return m;
}
// Build a resource.notify message
Message* Client::buildNotify(bool online, const String& account, const ClientResource* from)
{
Message* m = buildMessage("resource.notify",account,online ? "online" : "offline");
if (from) {
m->addParam("priority",String(from->m_priority));
m->addParam("status",from->m_text);
if (from->m_status > ClientResource::Online)
m->addParam("show",lookup(from->m_status,ClientResource::s_statusName));
}
return m;
}
// Build a resource.subscribe or resource.notify message to request a subscription
// or respond to a request
Message* Client::buildSubscribe(bool request, bool ok, const String& account,
const String& contact, const char* proto)
{
Message* m = 0;
if (request)
m = buildMessage("resource.subscribe",account,ok ? "subscribe" : "unsubscribe");
else
m = buildMessage("resource.notify",account,ok ? "subscribed" : "unsubscribed");
if (!TelEngine::null(proto))
m->addParam("protocol",proto);
m->addParam("to",contact);
return m;
}
// Build an user.roster message
Message* Client::buildUserRoster(bool update, const String& account,
const String& contact, const char* proto)
{
Message* m = buildMessage("user.roster",account,update ? "update" : "delete");
if (!TelEngine::null(proto))
m->addParam("protocol",proto);
m->addParam("contact",contact);
return m;
}
// Add a new module for handling actions
bool Client::addLogic(ClientLogic* logic)
{
@ -3090,7 +3152,7 @@ bool ClientDriver::received(Message& msg, int id)
return true;
}
if (id == ImExecute || id == Text) {
if (name() == msg.getValue("module"))
if (Client::isClientMsg(msg))
return false;
return Client::self() && Client::self()->imExecute(msg);
}

View File

@ -1122,6 +1122,13 @@ public:
static inline bool valid()
{ return self() && (self() == Thread::current() || !(exiting() || Engine::exiting())); }
/**
* Check if a message is sent by the client
* @param msg The message to check
* @return True if the message has a 'module' parameter with the client driver's name
*/
static bool isClientMsg(Message& msg);
inline static bool changing()
{ return (s_changing > 0); }
static Window* getWindow(const String& name);
@ -1334,6 +1341,51 @@ public:
static inline bool exiting()
{ return s_exiting; }
/**
* Build a message to be sent by the client.
* Add module, line and operation parameters
* @param msg Message name
* @param account The account sending the message
* @param oper Optional operation parameter
* @return Message pointer
*/
static Message* buildMessage(const char* msg, const String& account,
const char* oper = 0);
/**
* Build a resource.notify message
* @param online True to build an 'online' message, false to build an 'offline' one
* @param account The account sending the message
* @param from Optional resource to add to message
* @return Message pointer
*/
static Message* buildNotify(bool online, const String& account,
const ClientResource* from = 0);
/**
* Build a resource.subscribe or resource.notify message to request a subscription
* or respond to a request
* @param request True to build a request, false to build a response
* @param ok True to build a subscribe(d) message, false to build an unsubscribe(d) message
* @param account The account to use for the message
* @param contact The destination contact
* @param proto Optional protocol
* @return Valid Message pointer
*/
static Message* buildSubscribe(bool request, bool ok, const String& account,
const String& contact, const char* proto = 0);
/**
* Build an user.roster message
* @param update True to build an update, false to build a delete request
* @param account The account to use for the message
* @param contact The contact to update or delete
* @param proto Optional protocol
* @return Valid Message pointer
*/
static Message* buildUserRoster(bool update, const String& account,
const String& contact, const char* proto = 0);
/**
* Add a logic to the list. The added object is not owned by the client
* @param logic Pointer to the logic to add