* #29736: presence: Add getSubscriptions and setSubscriptions methods

parent cbc813d4
......@@ -4,92 +4,133 @@
<interface name="org.sflphone.SFLphone.PresenceManager">
<!-- METHODS !-->
<method name="sendPresence" tp:name-for-bindings="sendPresence">
<tp:added version="1.3.0"/>
<arg type="s" name="accountID" direction="in">
<tp:docstring>
The account from which the presence will be emitted
</tp:docstring>
</arg>
<arg type="b" name="status" direction="in">
<tp:docstring>
Is this account present or not
</tp:docstring>
</arg>
<arg type="s" name="note" direction="in">
<tp:docstring>
A message transmitted by the server to other users
</tp:docstring>
</arg>
<tp:added version="1.3.0"/>
<arg type="s" name="accountID" direction="in">
<tp:docstring>
The account from which the presence will be emitted
</tp:docstring>
</arg>
<arg type="b" name="status" direction="in">
<tp:docstring>
Is this account present or not
</tp:docstring>
</arg>
<arg type="s" name="note" direction="in">
<tp:docstring>
A message transmitted by the server to other users
</tp:docstring>
</arg>
</method>
<method name="approvePresSubServer" tp:name-for-bindings="approvePresSubServer">
<tp:docstring>
Answer a presence request from the server
</tp:docstring>
<tp:added version="1.3.0"/>
<arg type="s" name="uri" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
<arg type="b" name="flag" direction="in">
<tp:docstring>
Is the request granted or denied
</tp:docstring>
</arg>
<tp:docstring>
Answer a presence request from the server
</tp:docstring>
<tp:added version="1.3.0"/>
<arg type="s" name="uri" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
<arg type="b" name="flag" direction="in">
<tp:docstring>
Is the request granted or denied
</tp:docstring>
</arg>
</method>
<method name="subscribeClient" tp:name-for-bindings="subscribeClient">
<tp:docstring>
Ask be be notified when 'uri' presence change
</tp:docstring>
<tp:added version="1.3.0"/>
<arg type="s" name="accountID" direction="in">
<tp:docstring>
An account from which get request presence informations
</tp:docstring>
</arg>
<arg type="s" name="uri" direction="in">
<tp:docstring>
A SIP uri to watch
</tp:docstring>
</arg>
<arg type="b" name="flag" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="subscribePresSubClient" tp:name-for-bindings="subscribePresSubClient">
<tp:docstring>
Ask be be notified when 'uri' presence change
</tp:docstring>
<tp:added version="1.3.0"/>
<arg type="s" name="accountID" direction="in">
<tp:docstring>
An account from which get request presence informations
<method name="getSubscriptions" tp:name-for-bindings="getSubscriptions">
<tp:added version="1.3.0"/>
<tp:rationale>
New clients connecting to existing daemon need to be aware of active
subscriptions.
</tp:rationale>
<annotation name="com.trolltech.QtDBus.QtTypeName.In0" value="VectorMapStringString"/>
<annotation>
While there is more status than "Online" or "Offline", only those
</annotation>
<arg type="s" name="accountID" direction="in">
</arg>
<arg type="aa{ss}" name="credentialInformation" direction="out" tp:type="String_String_Map">
<tp:docstring>
List of hashes map with the following key-value pairs:
* Status: "Online" or "Offline"
* LineStatus: String
</tp:docstring>
</arg>
<arg type="s" name="uri" direction="in">
<tp:docstring>
A SIP uri to watch
</arg>
</method>
<method name="setSubscriptions" tp:name-for-bindings="setSubscriptions">
<tp:added version="1.3.0"/>
<tp:rationale>Calling "subscribeClient" in a loop is too slow</tp:rationale>
<arg type="s" name="accountID" direction="in">
</arg>
<annotation name="com.trolltech.QtDBus.QtTypeName.In1" value="VectorString"/>
<arg type="as" name="uriList" direction="in">
<tp:docstring>
A list of SIP URIs
</tp:docstring>
</arg>
<arg type="b" name="flag" direction="in">
<tp:docstring>
</arg>
<!--TODO<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="VectorString"/>
<arg type="as" name="invalidUris" direction="out">
<tp:docstring>
List of invalid URIs. An URI must be a valid SIP URI. Clients should purge
the list from all invalid URIs
</tp:docstring>
</arg>
</arg>-->
</method>
<!-- SIGNALS !-->
<signal name="newPresSubClientNotification" tp:name-for-bindings="newPresSubClientNotification">
<tp:added version="1.3.0"/>
<tp:docstring>
Notify when a registered presence uri presence informations changes
</tp:docstring>
<arg type="s" name="buddyUri">
<tp:docstring>
The registered URI
</tp:docstring>
</arg>
<arg type="b" name="status">
<tp:docstring>
Is the URI present or not
</tp:docstring>
</arg>
<arg type="s" name="lineStatus">
<tp:docstring>
A string containing informations from the user (human readable)
</tp:docstring>
</arg>
<tp:added version="1.3.0"/>
<tp:docstring>
Notify when a registered presence uri presence informations changes
</tp:docstring>
<arg type="s" name="buddyUri">
<tp:docstring>
The registered URI
</tp:docstring>
</arg>
<arg type="b" name="status">
<tp:docstring>
Is the URI present or not
</tp:docstring>
</arg>
<arg type="s" name="lineStatus">
<tp:docstring>
A string containing informations from the user (human readable)
</tp:docstring>
</arg>
</signal>
<signal name="newPresSubServerRequest" tp:name-for-bindings="newPresSubServerRequest">
<tp:added version="1.3.0"/>
<arg type="s" name="buddyUri">
<tp:docstring>
Notify when an other user (or the server) request your presence informations
</tp:docstring>
</arg>
<tp:added version="1.3.0"/>
<arg type="s" name="buddyUri">
<tp:docstring>
Notify when an other user (or the server) request your presence informations
</tp:docstring>
</arg>
</signal>
</interface>
</node>
......@@ -41,9 +41,14 @@
#include "sip/sipaccount.h"
#include "manager.h"
#include "sip/sippresence.h"
#include "sip/pres_sub_client.h"
namespace {
const char* SERVER_PATH = "/org/sflphone/SFLphone/PresenceManager";
constexpr static const char* SERVER_PATH = "/org/sflphone/SFLphone/PresenceManager";
constexpr static const char* STATUS_KEY = "Status";
constexpr static const char* LINESTATUS_KEY = "LineStatus";
constexpr static const char* ONLINE_KEY = "Online";
constexpr static const char* OFFLINE_KEY = "Offline";
}
PresenceManager::PresenceManager(DBus::Connection& connection) :
......@@ -54,7 +59,7 @@ PresenceManager::PresenceManager(DBus::Connection& connection) :
* Un/subscribe to buddySipUri for an accountID
*/
void
PresenceManager::subscribePresSubClient(const std::string& accountID, const std::string& uri, const bool& flag)
PresenceManager::subscribeClient(const std::string& accountID, const std::string& uri, const bool& flag)
{
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
......@@ -62,7 +67,7 @@ PresenceManager::subscribePresSubClient(const std::string& accountID, const std:
ERROR("Could not find account %s",accountID.c_str());
else{
DEBUG("%subscribePresence (acc:%s, buddy:%s)",flag? "S":"Uns", accountID.c_str(), uri.c_str());
sipaccount->getPresence()->subscribePresSubClient(uri,flag);
sipaccount->getPresence()->subscribeClient(uri,flag);
}
}
......@@ -96,3 +101,34 @@ PresenceManager::approvePresSubServer(const std::string& uri, const bool& flag)
sipaccount->getPresence()->approvePresSubServer(uri, flag);
}
}
/**
* Get all active subscriptions for "accountID"
*/
std::vector<std::map<std::string, std::string> >
PresenceManager::getSubscriptions(const std::string& accountID)
{
std::vector<std::map<std::string, std::string> > ret;
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
if (sipaccount) {
for (auto s : sipaccount->getPresence()->getClientSubscriptions()) {
std::map<std::string, std::string> sub;
sub[ STATUS_KEY ] = s->isPresent()?ONLINE_KEY:OFFLINE_KEY;
sub[ LINESTATUS_KEY ] = s->getLineStatus();
ret.push_back(sub);
}
}
return ret;
}
/**
* Batch subscribing of URIs
*/
void
PresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris)
{
SIPAccount *sipaccount = Manager::instance().getSipAccount(accountID);
for (auto u:uris) {
sipaccount->getPresence()->subscribeClient(u,true);
}
}
\ No newline at end of file
......@@ -84,7 +84,9 @@ class PresenceManager
/* Presence subscription/Notification. */
void sendPresence(const std::string& accountID, const bool& status, const std::string& note);
void approvePresSubServer(const std::string& uri, const bool& flag);
void subscribePresSubClient(const std::string& accountID, const std::string& uri, const bool& flag);
void subscribeClient(const std::string& accountID, const std::string& uri, const bool& flag);
std::vector<std::map<std::string, std::string> > getSubscriptions(const std::string& accountID);
void setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris);
};
......
......@@ -298,6 +298,14 @@ std::string PresSubClient::getURI() {
return res;
}
bool PresSubClient::isPresent() {
return status.info[0].basic_open;
}
std::string PresSubClient::getLineStatus() {
return std::string(status.info[0].rpid.note.ptr,status.info[0].rpid.note.slen);
}
bool PresSubClient::isTermReason(std::string reason) {
std::string myReason(term_reason.ptr, term_reason.slen);
return !myReason.compare(reason);
......
......@@ -101,6 +101,16 @@ class PresSubClient {
*/
std::string getURI();
/**
* Is the URI present
*/
bool isPresent();
/**
* A message from the URIs
*/
std::string getLineStatus();
friend void pres_client_evsub_on_state(pjsip_evsub *sub, pjsip_event *event);
friend void pres_client_evsub_on_tsx_state(pjsip_evsub *sub,
......
......@@ -144,7 +144,7 @@ void SIPPresence::reportPresSubClientNotification(const std::string& uri, pjsip_
Manager::instance().getClient()->getPresenceManager()->newPresSubClientNotification(uri, status->info[0].basic_open, note);
}
void SIPPresence::subscribePresSubClient(const std::string& uri, const bool& flag){
void SIPPresence::subscribeClient(const std::string& uri, const bool& flag){
/* Check if the buddy was already subscribed */
for(auto c : pres_sub_client_list_)
if(c->getURI()==uri){
......
......@@ -158,7 +158,7 @@ public:
* Send a SUBSCRIBE request to PBX/IP2IP
* @param buddyUri Remote user that we want to subscribe
*/
void subscribePresSubClient(const std::string& uri, const bool& flag);
void subscribeClient(const std::string& uri, const bool& flag);
/**
* Add a buddy in the buddy list.
* @param b PresSubClient pointer
......@@ -200,11 +200,15 @@ public:
* Iterate through the subscriber list and send NOTIFY to each.
*/
void notifyPresSubServer();
bool isEnabled() const {
return enabled;
}
const std::list< PresSubClient *> getClientSubscriptions() {
return pres_sub_client_list_;
}
/**
* Lock methods
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment