Commit 56b791cc authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Alexandre Lision

api: refactoring public API

Rationale:
Current API is a bit over-engineered and not permit evolution.
Moreover it's not designed to be straightforward mapped within
a C library if users want it.
Fine-grained and no-throwable API permit to fix that.

Refs #68589

Change-Id: I4fc5566077ee748446ae014a81375d09120e65de
parent ef9c6272
......@@ -31,7 +31,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#endif // HAVE_CONFIG_H
#include <cstdlib>
#include <iostream>
......@@ -84,7 +84,7 @@ DBusClient::DBusClient(int sflphFlags, bool persistent)
// destructor, so we must NOT delete them ourselves.
timeout_.reset(new DBus::DefaultTimeout {10 /* ms */, true, dispatcher_.get()});
// Poll for Deamon events
timeout_->expired = new EventCallback {DRing::poll_events};
timeout_->expired = new EventCallback {DRing::pollEvents};
DBus::Connection sessionConnection {DBus::Connection::SessionBus()};
sessionConnection.request_name("cx.ring.Ring");
......@@ -127,7 +127,8 @@ DBusClient::~DBusClient()
timeout_.reset();
}
int DBusClient::initLibrary(int sflphFlags)
int
DBusClient::initLibrary(int sflphFlags)
{
using namespace std::placeholders;
......@@ -148,66 +149,74 @@ int DBusClient::initLibrary(int sflphFlags)
auto videoM = videoManager_.get();
#endif
const std::map<DRing::EventHandlerKey, std::map<std::string, SharedCallback>> evHandlers = {
{ // Call event handlers
DRing::EventHandlerKey::CALL, {
exportable_callback<CallSignal::StateChange>(bind(&DBusCallManager::callStateChanged, callM, _1, _2)),
exportable_callback<CallSignal::TransferFailed>(bind(&DBusCallManager::transferFailed, callM)),
exportable_callback<CallSignal::TransferSucceeded>(bind(&DBusCallManager::transferSucceeded, callM)),
exportable_callback<CallSignal::RecordPlaybackStopped>(bind(&DBusCallManager::recordPlaybackStopped, callM, _1)),
exportable_callback<CallSignal::VoiceMailNotify>(bind(&DBusCallManager::voiceMailNotify, callM, _1, _2)),
exportable_callback<CallSignal::IncomingMessage>(bind(&DBusCallManager::incomingMessage, callM, _1, _2, _3)),
exportable_callback<CallSignal::IncomingCall>(bind(&DBusCallManager::incomingCall, callM, _1, _2, _3)),
exportable_callback<CallSignal::RecordPlaybackFilepath>(bind(&DBusCallManager::recordPlaybackFilepath, callM, _1, _2)),
exportable_callback<CallSignal::ConferenceCreated>(bind(&DBusCallManager::conferenceCreated, callM, _1)),
exportable_callback<CallSignal::ConferenceChanged>(bind(&DBusCallManager::conferenceChanged, callM, _1, _2)),
exportable_callback<CallSignal::UpdatePlaybackScale>(bind(&DBusCallManager::updatePlaybackScale, callM, _1, _2, _3)),
exportable_callback<CallSignal::ConferenceRemoved>(bind(&DBusCallManager::conferenceRemoved, callM, _1)),
exportable_callback<CallSignal::NewCallCreated>(bind(&DBusCallManager::newCallCreated, callM, _1, _2, _3)),
exportable_callback<CallSignal::SipCallStateChanged>(bind(&DBusCallManager::sipCallStateChanged, callM, _1, _2, _3)),
exportable_callback<CallSignal::RecordingStateChanged>(bind(&DBusCallManager::recordingStateChanged, callM, _1, _2)),
exportable_callback<CallSignal::SecureSdesOn>(bind(&DBusCallManager::secureSdesOn, callM, _1)),
exportable_callback<CallSignal::SecureSdesOff>(bind(&DBusCallManager::secureSdesOff, callM, _1)),
exportable_callback<CallSignal::SecureZrtpOn>(bind(&DBusCallManager::secureZrtpOn, callM, _1, _2)),
exportable_callback<CallSignal::SecureZrtpOff>(bind(&DBusCallManager::secureZrtpOff, callM, _1)),
exportable_callback<CallSignal::ShowSAS>(bind(&DBusCallManager::showSAS, callM, _1, _2, _3)),
exportable_callback<CallSignal::ZrtpNotSuppOther>(bind(&DBusCallManager::zrtpNotSuppOther, callM, _1)),
exportable_callback<CallSignal::ZrtpNegotiationFailed>(bind(&DBusCallManager::zrtpNegotiationFailed, callM, _1, _2, _3)),
exportable_callback<CallSignal::RtcpReportReceived>(bind(&DBusCallManager::onRtcpReportReceived, callM, _1, _2)),
}
},
{ // Configuration event handlers
DRing::EventHandlerKey::CONFIG, {
exportable_callback<ConfigurationSignal::VolumeChanged>(bind(&DBusConfigurationManager::volumeChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::AccountsChanged>(bind(&DBusConfigurationManager::accountsChanged, confM)),
exportable_callback<ConfigurationSignal::StunStatusFailed>(bind(&DBusConfigurationManager::stunStatusFailure, confM, _1)),
exportable_callback<ConfigurationSignal::RegistrationStateChanged>(bind(&DBusConfigurationManager::registrationStateChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::SipRegistrationStateChanged>(bind(&DBusConfigurationManager::sipRegistrationStateChanged, confM, _1, _2, _3)),
exportable_callback<ConfigurationSignal::VolatileDetailsChanged>(bind(&DBusConfigurationManager::volatileAccountDetailsChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::Error>(bind(&DBusConfigurationManager::errorAlert, confM, _1)),
}
},
{ // Presence event handlers
DRing::EventHandlerKey::PRESENCE, {
exportable_callback<PresenceSignal::NewServerSubscriptionRequest>(bind(&DBusPresenceManager::newServerSubscriptionRequest, presM, _1)),
exportable_callback<PresenceSignal::ServerError>(bind(&DBusPresenceManager::serverError, presM, _1, _2, _3)),
exportable_callback<PresenceSignal::NewBuddyNotification>(bind(&DBusPresenceManager::newBuddyNotification, presM, _1, _2, _3, _4)),
exportable_callback<PresenceSignal::SubscriptionStateChanged>(bind(&DBusPresenceManager::subscriptionStateChanged, presM, _1, _2, _3)),
}
},
// Call event handlers
const std::map<std::string, SharedCallback> callEvHandlers = {
exportable_callback<CallSignal::StateChange>(bind(&DBusCallManager::callStateChanged, callM, _1, _2)),
exportable_callback<CallSignal::TransferFailed>(bind(&DBusCallManager::transferFailed, callM)),
exportable_callback<CallSignal::TransferSucceeded>(bind(&DBusCallManager::transferSucceeded, callM)),
exportable_callback<CallSignal::RecordPlaybackStopped>(bind(&DBusCallManager::recordPlaybackStopped, callM, _1)),
exportable_callback<CallSignal::VoiceMailNotify>(bind(&DBusCallManager::voiceMailNotify, callM, _1, _2)),
exportable_callback<CallSignal::IncomingMessage>(bind(&DBusCallManager::incomingMessage, callM, _1, _2, _3)),
exportable_callback<CallSignal::IncomingCall>(bind(&DBusCallManager::incomingCall, callM, _1, _2, _3)),
exportable_callback<CallSignal::RecordPlaybackFilepath>(bind(&DBusCallManager::recordPlaybackFilepath, callM, _1, _2)),
exportable_callback<CallSignal::ConferenceCreated>(bind(&DBusCallManager::conferenceCreated, callM, _1)),
exportable_callback<CallSignal::ConferenceChanged>(bind(&DBusCallManager::conferenceChanged, callM, _1, _2)),
exportable_callback<CallSignal::UpdatePlaybackScale>(bind(&DBusCallManager::updatePlaybackScale, callM, _1, _2, _3)),
exportable_callback<CallSignal::ConferenceRemoved>(bind(&DBusCallManager::conferenceRemoved, callM, _1)),
exportable_callback<CallSignal::NewCallCreated>(bind(&DBusCallManager::newCallCreated, callM, _1, _2, _3)),
exportable_callback<CallSignal::SipCallStateChanged>(bind(&DBusCallManager::sipCallStateChanged, callM, _1, _2, _3)),
exportable_callback<CallSignal::RecordingStateChanged>(bind(&DBusCallManager::recordingStateChanged, callM, _1, _2)),
exportable_callback<CallSignal::SecureSdesOn>(bind(&DBusCallManager::secureSdesOn, callM, _1)),
exportable_callback<CallSignal::SecureSdesOff>(bind(&DBusCallManager::secureSdesOff, callM, _1)),
exportable_callback<CallSignal::SecureZrtpOn>(bind(&DBusCallManager::secureZrtpOn, callM, _1, _2)),
exportable_callback<CallSignal::SecureZrtpOff>(bind(&DBusCallManager::secureZrtpOff, callM, _1)),
exportable_callback<CallSignal::ShowSAS>(bind(&DBusCallManager::showSAS, callM, _1, _2, _3)),
exportable_callback<CallSignal::ZrtpNotSuppOther>(bind(&DBusCallManager::zrtpNotSuppOther, callM, _1)),
exportable_callback<CallSignal::ZrtpNegotiationFailed>(bind(&DBusCallManager::zrtpNegotiationFailed, callM, _1, _2, _3)),
exportable_callback<CallSignal::RtcpReportReceived>(bind(&DBusCallManager::onRtcpReportReceived, callM, _1, _2)),
};
// Configuration event handlers
const std::map<std::string, SharedCallback> configEvHandlers = {
exportable_callback<ConfigurationSignal::VolumeChanged>(bind(&DBusConfigurationManager::volumeChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::AccountsChanged>(bind(&DBusConfigurationManager::accountsChanged, confM)),
exportable_callback<ConfigurationSignal::StunStatusFailed>(bind(&DBusConfigurationManager::stunStatusFailure, confM, _1)),
exportable_callback<ConfigurationSignal::RegistrationStateChanged>(bind(&DBusConfigurationManager::registrationStateChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::SipRegistrationStateChanged>(bind(&DBusConfigurationManager::sipRegistrationStateChanged, confM, _1, _2, _3)),
exportable_callback<ConfigurationSignal::VolatileDetailsChanged>(bind(&DBusConfigurationManager::volatileAccountDetailsChanged, confM, _1, _2)),
exportable_callback<ConfigurationSignal::Error>(bind(&DBusConfigurationManager::errorAlert, confM, _1)),
};
// Presence event handlers
const std::map<std::string, SharedCallback> presEvHandlers = {
exportable_callback<PresenceSignal::NewServerSubscriptionRequest>(bind(&DBusPresenceManager::newServerSubscriptionRequest, presM, _1)),
exportable_callback<PresenceSignal::ServerError>(bind(&DBusPresenceManager::serverError, presM, _1, _2, _3)),
exportable_callback<PresenceSignal::NewBuddyNotification>(bind(&DBusPresenceManager::newBuddyNotification, presM, _1, _2, _3, _4)),
exportable_callback<PresenceSignal::SubscriptionStateChanged>(bind(&DBusPresenceManager::subscriptionStateChanged, presM, _1, _2, _3)),
};
#ifdef RING_VIDEO
{ // Video event handlers
DRing::EventHandlerKey::VIDEO, {
exportable_callback<VideoSignal::DeviceEvent>(bind(&DBusVideoManager::deviceEvent, videoM)),
exportable_callback<VideoSignal::DecodingStarted>(bind(&DBusVideoManager::startedDecoding, videoM, _1, _2, _3, _4, _5)),
exportable_callback<VideoSignal::DecodingStopped>(bind(&DBusVideoManager::stoppedDecoding, videoM, _1, _2, _3)),
}
},
#endif
// Video event handlers
const std::map<std::string, SharedCallback> videoEvHandlers = {
exportable_callback<VideoSignal::DeviceEvent>(bind(&DBusVideoManager::deviceEvent, videoM)),
exportable_callback<VideoSignal::DecodingStarted>(bind(&DBusVideoManager::startedDecoding, videoM, _1, _2, _3, _4, _5)),
exportable_callback<VideoSignal::DecodingStopped>(bind(&DBusVideoManager::stoppedDecoding, videoM, _1, _2, _3)),
};
#endif
// Initialize now
return (unsigned)DRing::init(evHandlers, static_cast<DRing::InitFlag>(sflphFlags));
if (!DRing::init(static_cast<DRing::InitFlag>(sflphFlags)))
return -1;
registerCallHandlers(callEvHandlers);
registerConfHandlers(configEvHandlers);
registerPresHandlers(presEvHandlers);
#ifdef RING_VIDEO
registerVideoHandlers(videoEvHandlers);
#endif
if (!DRing::start())
return -1;
return 0;
}
void
......
......@@ -147,11 +147,19 @@ osxTests()
{
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
DRing::init(std::map<DRing::EventHandlerKey, std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>>>(),
static_cast<DRing::InitFlag>(ringFlags));
DRing::init(static_cast<DRing::InitFlag>(ringFlags));
registerCallHandlers(std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>>());
registerConfHandlers(std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>>());
registerPresHandlers(std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>>());
#ifdef RING_VIDEO
registerVideoHandlers(std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>>());
#endif
if (!DRing::start())
return -1;
while (true) {
DRing::poll_events();
DRing::pollEvents();
sleep(1);
}
......
......@@ -337,8 +337,7 @@ void
sendTextMessage(const std::string& callID, const std::string& message)
{
#if HAVE_INSTANT_MESSAGING
if (!ring::Manager::instance().sendTextMessage(callID, message, "Me"))
throw CallManagerException();
ring::Manager::instance().sendTextMessage(callID, message, "Me");
#else
RING_ERR("Could not send \"%s\" text message to %s since SFLphone daemon does not support it, please recompile with instant messaging support", message.c_str(), callID.c_str());
#endif
......
......@@ -43,11 +43,66 @@
namespace DRing {
class CallManagerException: public std::runtime_error {
public:
CallManagerException(const std::string& str = "") :
std::runtime_error("A CallManagerException occured: " + str) {}
};
void registerCallHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
/* Call related methods */
std::string placeCall(const std::string& accountID, const std::string& to);
bool refuse(const std::string& callID);
bool accept(const std::string& callID);
bool hangUp(const std::string& callID);
bool hold(const std::string& callID);
bool unhold(const std::string& callID);
bool transfer(const std::string& callID, const std::string& to);
bool attendedTransfer(const std::string& transferID, const std::string& targetID);
std::map<std::string, std::string> getCallDetails(const std::string& callID);
std::vector<std::string> getCallList();
/* Conference related methods */
void removeConference(const std::string& conference_id);
bool joinParticipant(const std::string& sel_callID, const std::string& drag_callID);
void createConfFromParticipantList(const std::vector<std::string>& participants);
bool isConferenceParticipant(const std::string& call_id);
bool addParticipant(const std::string& callID, const std::string& confID);
bool addMainParticipant(const std::string& confID);
bool detachParticipant(const std::string& callID);
bool joinConference(const std::string& sel_confID, const std::string& drag_confID);
bool hangUpConference(const std::string& confID);
bool holdConference(const std::string& confID);
bool unholdConference(const std::string& confID);
std::vector<std::string> getConferenceList();
std::vector<std::string> getParticipantList(const std::string& confID);
std::vector<std::string> getDisplayNames(const std::string& confID);
std::string getConferenceId(const std::string& callID);
std::map<std::string, std::string> getConferenceDetails(const std::string& callID);
/* File Playback methods */
bool startRecordedFilePlayback(const std::string& filepath);
void stopRecordedFilePlayback(const std::string& filepath);
/* General audio methods */
bool toggleRecording(const std::string& callID);
/* DEPRECATED */
void setRecording(const std::string& callID);
void recordPlaybackSeek(double value);
bool getIsRecording(const std::string& callID);
std::string getCurrentAudioCodecName(const std::string& callID);
void playDTMF(const std::string& key);
void startTone(int32_t start, int32_t type);
bool switchInput(const std::string& callID, const std::string& resource);
/* Security related methods */
void setSASVerified(const std::string& callID);
void resetSASVerified(const std::string& callID);
void setConfirmGoClear(const std::string& callID);
void requestGoClear(const std::string& callID);
void acceptEnrollment(const std::string& callID, bool accepted);
/* Instant messaging */
void sendTextMessage(const std::string& callID, const std::string& message);
void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
// Call signal type definitions
struct CallSignal {
......@@ -145,67 +200,6 @@ struct CallSignal {
};
};
void registerCallHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
/* Call related methods */
std::string placeCall(const std::string& accountID, const std::string& to);
bool refuse(const std::string& callID);
bool accept(const std::string& callID);
bool hangUp(const std::string& callID);
bool hold(const std::string& callID);
bool unhold(const std::string& callID);
bool transfer(const std::string& callID, const std::string& to);
bool attendedTransfer(const std::string& transferID, const std::string& targetID);
std::map<std::string, std::string> getCallDetails(const std::string& callID);
std::vector<std::string> getCallList();
/* Conference related methods */
void removeConference(const std::string& conference_id);
bool joinParticipant(const std::string& sel_callID, const std::string& drag_callID);
void createConfFromParticipantList(const std::vector<std::string>& participants);
bool isConferenceParticipant(const std::string& call_id);
bool addParticipant(const std::string& callID, const std::string& confID);
bool addMainParticipant(const std::string& confID);
bool detachParticipant(const std::string& callID);
bool joinConference(const std::string& sel_confID, const std::string& drag_confID);
bool hangUpConference(const std::string& confID);
bool holdConference(const std::string& confID);
bool unholdConference(const std::string& confID);
std::vector<std::string> getConferenceList();
std::vector<std::string> getParticipantList(const std::string& confID);
std::vector<std::string> getDisplayNames(const std::string& confID);
std::string getConferenceId(const std::string& callID);
std::map<std::string, std::string> getConferenceDetails(const std::string& callID);
/* File Playback methods */
bool startRecordedFilePlayback(const std::string& filepath);
void stopRecordedFilePlayback(const std::string& filepath);
/* General audio methods */
bool toggleRecording(const std::string& callID);
/* DEPRECATED */
void setRecording(const std::string& callID);
void recordPlaybackSeek(double value);
bool getIsRecording(const std::string& callID);
std::string getCurrentAudioCodecName(const std::string& callID);
void playDTMF(const std::string& key);
void startTone(int32_t start, int32_t type);
bool switchInput(const std::string& callID, const std::string& resource);
/* Security related methods */
void setSASVerified(const std::string& callID);
void resetSASVerified(const std::string& callID);
void setConfirmGoClear(const std::string& callID);
void requestGoClear(const std::string& callID);
void acceptEnrollment(const std::string& callID, bool accepted);
/* Instant messaging */
void sendTextMessage(const std::string& callID, const std::string& message);
void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from);
} // namespace DRing
#endif // DRING_CALLMANAGERI_H
......@@ -45,39 +45,6 @@
namespace DRing {
// Configuration signal type definitions
struct ConfigurationSignal {
struct VolumeChanged {
constexpr static const char* name = "VolumeChanged";
using cb_type = void(const std::string& /*device*/, double /*value*/);
};
struct AccountsChanged {
constexpr static const char* name = "AccountsChanged";
using cb_type = void(void);
};
struct StunStatusFailed {
constexpr static const char* name = "StunStatusFailed";
using cb_type = void(const std::string& /*account_id*/);
};
struct RegistrationStateChanged {
constexpr static const char* name = "RegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/, int /*state*/);
};
struct SipRegistrationStateChanged {
constexpr static const char* name = "SipRegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/, const std::string& /*state*/, int /*code*/);
};
struct VolatileDetailsChanged {
constexpr static const char* name = "VolatileDetailsChanged";
using cb_type = void(const std::string& /*account_id*/, const std::map<std::string, std::string>& /* details */);
};
struct Error {
constexpr static const char* name = "Error";
using cb_type = void(int /*alert*/);
};
};
void registerConfHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
std::map<std::string, std::string> getAccountDetails(const std::string& accountID);
......@@ -170,6 +137,38 @@ std::map<std::string, std::string> validateCertificateRaw(const std::string& acc
std::map<std::string, std::string> getCertificateDetails(const std::string& certificate);
std::map<std::string, std::string> getCertificateDetailsRaw(const std::vector<uint8_t>& certificate);
// Configuration signal type definitions
struct ConfigurationSignal {
struct VolumeChanged {
constexpr static const char* name = "VolumeChanged";
using cb_type = void(const std::string& /*device*/, double /*value*/);
};
struct AccountsChanged {
constexpr static const char* name = "AccountsChanged";
using cb_type = void(void);
};
struct StunStatusFailed {
constexpr static const char* name = "StunStatusFailed";
using cb_type = void(const std::string& /*account_id*/);
};
struct RegistrationStateChanged {
constexpr static const char* name = "RegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/, int /*state*/);
};
struct SipRegistrationStateChanged {
constexpr static const char* name = "SipRegistrationStateChanged";
using cb_type = void(const std::string& /*account_id*/, const std::string& /*state*/, int /*code*/);
};
struct VolatileDetailsChanged {
constexpr static const char* name = "VolatileDetailsChanged";
using cb_type = void(const std::string& /*account_id*/, const std::map<std::string, std::string>& /* details */);
};
struct Error {
constexpr static const char* name = "Error";
using cb_type = void(int /*alert*/);
};
};
} // namespace DRing
#endif // DRING_CONFIGURATIONMANAGERI_H
......@@ -40,20 +40,44 @@
namespace DRing {
enum class EventHandlerKey { CALL, CONFIG, PRESENCE, VIDEO };
/* error codes returned by functions of this API */
enum class InitResult {
SUCCESS=0,
ERR_MANAGER_INIT,
};
/* flags for initialization */
enum InitFlag {
DRING_FLAG_DEBUG=1,
DRING_FLAG_CONSOLE_LOG=2,
};
/**
* Return the library version as string.
*/
const char* version() noexcept;
/**
* Initialize globals, create underlaying daemon.
*
* @param flags Flags to customize this initialization
* @returns true if initialization succeed else false.
*/
bool init(enum InitFlag flags) noexcept;
/**
* Start asynchronously daemon created by init().
* @returns true if daemon started successfuly
*/
bool start(const std::string& config_file={}) noexcept;
/**
* Stop and freeing any resource allocated by daemon
*/
void fini() noexcept;
/**
* Poll daemon events.
* This function has to be called by user at a fixed frequency
* to let daemon checks its internal ressources and io and
* manages events reported by them.
*/
void pollEvents() noexcept;
/* External Callback Dynamic Utilities
*
* The library provides to users a way to be acknowledged
......@@ -61,11 +85,11 @@ enum InitFlag {
* The user is aware of this changement wen the deamon calls
* a user-given callback.
* Daemon handles many of these callbacks, one per event type.
* The user registers his callback when he calls daemon DRing:init().
* Each callback has its own function signature.
* To keep ABI compatibility we don't let user directly provides
* The user registers his callbacks using registerXXXXHandlers() functions.
* As each callback has its own function signature,
* to keep compatibility over releases we don't let user directly provides
* his callbacks as it or through a structure.
* This way bring ABI violation if we need to change the order
* This way brings ABI violation if we need to change the order
* and/or the existance of any callback type.
* Thus the user have to pass them using following template classes
* and functions, that wraps user-callback in a generic and ABI-compatible way.
......@@ -121,41 +145,20 @@ class CallbackWrapper : public CallbackWrapperBase {
}
};
// Return an exportable callback object.
// This object is a std::pair of a string and a CallbackWrapperBase shared_ptr.
// This last wraps given callback in a ABI-compatible way.
// Note: this version accepts callback as a rvalue.
/**
* Return an exportable callback object.
* This object is a std::pair of a string and a CallbackWrapperBase shared_ptr.
* This last wraps given callback in a ABI-compatible way.
* Note: this version accepts callbacks as rvalue only.
*/
template <typename Ts>
std::pair<std::string, std::shared_ptr<CallbackWrapperBase>>
exportable_callback(std::function<typename Ts::cb_type>&& func) {
return std::make_pair((const std::string&)Ts::name, std::make_shared<CallbackWrapper<typename Ts::cb_type>>(std::forward<std::function<typename Ts::cb_type>>(func)));
return std::make_pair((const std::string&)Ts::name,
std::make_shared<CallbackWrapper<typename Ts::cb_type>>
(std::forward<std::function<typename Ts::cb_type>>(func)));
}
/* Return the library version */
const char* version() noexcept;
/**
* Initializes libring.
*
* @param ev_handlers Event handlers
* @param flags Flags to customize this initialization
* @returns 0 if successful or a negative error code
*/
InitResult
init(const std::map<EventHandlerKey,
std::map<std::string, std::shared_ptr<CallbackWrapperBase>>>& ev_handlers,
enum InitFlag flags);
/**
* Finalizes libring, freeing any resource allocated by the library.
*/
void fini(void) noexcept;
/**
* Poll for Daemon events
*/
void poll_events(void);
} // namespace DRing
#endif /* DRING_H */
......@@ -40,6 +40,15 @@
namespace DRing {
void registerPresHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
/* Presence subscription/Notification. */
void publish(const std::string& accountID, bool status, const std::string& note);
void answerServerRequest(const std::string& uri, bool flag);
void subscribeBuddy(const std::string& accountID, const std::string& uri, 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);
// Presence signal type definitions
struct PresenceSignal {
struct NewServerSubscriptionRequest {
......@@ -60,15 +69,6 @@ struct PresenceSignal {
};
};
void registerPresHandlers(const std::map<std::string, std::shared_ptr<CallbackWrapperBase>>&);
/* Presence subscription/Notification. */
void publish(const std::string& accountID, bool status, const std::string& note);
void answerServerRequest(const std::string& uri, bool flag);
void subscribeBuddy(const std::string& accountID, const std::string& uri, 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);
} // namespace DRing
#endif //PRESENCEMANAGERI_H
......@@ -41,22 +41,6 @@ namespace DRing {
using VideoCapabilities = std::map<std::string, std::map<std::string, std::vector<std::string>>>;
// Video signal type definitions
struct VideoSignal {
struct DeviceEvent {
constexpr static const char* name = "DeviceEvent";
using cb_type = void(void);