client-cpp  0.6.3
User registration

Description

In order to have ability to send and (or) receive events an application must be attached to the user entity in Kaa ecosystem. User registration module gives API to manage endpoint-to-user attachments.

In scope of this C++ endpoint sdk provides next functionality:

If endpoint is assumed to be attached or detached by another application it is possible to set up callback for notifications when this endpoint becomes attached or detached. See Setting callbacks for attach/detach notifications.

All operations being described on this page are run in asynchronous mode. Thus, in order to retrieve result for each operation an appropriate callback should be registered. Callbacks for attach/detach operations must be inherited from kaa::IEndpointAttachStatusListener interface and passed to a relevant method.

Usage

Checking attachment status

To check if endpoint is attached to user invoke kaa::IEndpointRegistrationManager::isCurrentEndpointAttached() :

using namespace kaa;
bool isAttached = Kaa::getKaaClient().getEndpointRegistrationManager().isCurrentEndpointAttached();
...

Attaching current endpoint

To attach current application instance to a user invoke kaa::IEndpointRegistrationManager::attachUser(const std::string& userExternalId, const std::string& userAccessToken, IEndpointAttachStatusListener* listener)
Example:

using namespace kaa;
class DummyAttachListener : public IEndpointAttachStatusListener {
public:
void onAttachSuccess(const std::string& userExternalId, const std::string& endpointAccessToken) {
std::cout << "Attached to user" << std::endl;
}
void onAttachFailure() {
std::cout << "Failed to attach to user" << std::endl;
}
void onDetachSuccess(const std::string& endpointAccessToken) {
std::cout << "Detached from user" << std::endl;
}
void onDetachFailure() {
std::cout << "Failed to detach from user" << std::endl;
}
};
IEndpointAttachStatusListener listener = new DummyAttachListener();
std::string userExternalId = "devuser@foo.bar";
std::string userAccessToken = "devuser@foo.bar";
Kaa::getKaaClient().getEndpointRegistrationManager().attachUser(userExternalId, userAccessToken, listener);
...

Attaching other endpoint

To attach another application instance to a user invoke kaa::IEndpointRegistrationManager::attachEndpoint(const std::string& endpointAccessToken, IEndpointAttachStatusListener* listener)
Use endpoint access token - unique string identifier of an endpoint in Kaa ecosystem - to attach it to user.

NOTE: Only attached endpoints are allowed to attach other application instances to a user.
Example:

using namespace kaa;
class DummyAttachListener : public IEndpointAttachStatusListener {
public:
void onAttachSuccess(const std::string& userExternalId, const std::string& endpointAccessToken) {
std::cout << "Attached to user" << std::endl;
}
void onAttachFailure() {
std::cout << "Failed to attach to user" << std::endl;
}
void onDetachSuccess(const std::string& endpointAccessToken) {
std::cout << "Detached from user" << std::endl;
}
void onDetachFailure() {
std::cout << "Failed to detach from user" << std::endl;
}
};
IEndpointAttachStatusListener listener = new DummyAttachListener();
std::string endpointAccessToken = "10b1e314-b6be-49af-88ad-caf601815d93";
Kaa::getKaaClient().getEndpointRegistrationManager().attachEndpoint(endpointAccessToken, listener);
...

Detaching endpoint

Use endpoint key hash in order to detach endpoint from user entity.
NOTE: Only attached endpoints are allowed to detach other application instances from a user.

Detaching other endpoint by its public key hash:

using namespace kaa;
class DummyDetachListener : public IEndpointAttachStatusListener {
public:
void onAttachSuccess(const std::string& userExternalId, const std::string& endpointAccessToken) {
std::cout << "Attached to user" << std::endl;
}
void onAttachFailure() {
std::cout << "Failed to attach to user" << std::endl;
}
void onDetachSuccess(const std::string& endpointAccessToken) {
std::cout << "Detached from user" << std::endl;
}
void onDetachFailure() {
std::cout << "Failed to detach from user" << std::endl;
}
};
std::string epToDetach = "lZjEzq4E/D5aWjXYuG1N2sKYt/U="; // endpoint's public key hash.
IEndpointAttachStatusListener listener = new DummyDetachListener();
Kaa::getKaaClient().getEndpointRegistrationManager().detachEndpoint(epToDetach, listener);
...

Detaching current endpoint:

using namespace kaa;
class DummyDetachListener : public IEndpointAttachStatusListener {
public:
void onAttachSuccess(const std::string& userExternalId, const std::string& endpointAccessToken) {
std::cout << "Attached to user" << std::endl;
}
void onAttachFailure() {
std::cout << "Failed to attach to user" << std::endl;
}
void onDetachSuccess(const std::string& endpointAccessToken) {
std::cout << "Detached from user" << std::endl;
}
void onDetachFailure() {
std::cout << "Failed to detach from user" << std::endl;
}
};
IEndpointAttachStatusListener listener = new DummyDetachListener();
Kaa::getKaaClient().getEndpointRegistrationManager().detachEndpoint(listener);
...

Setting callbacks for attach/detach notifications

Set callback for attach/detach notification if assuming endpoint to be detached by other application instance:

using namespace kaa;
class DummyAttachNotificationListener : public IEndpointAttachStatusListener {
public:
void onAttachSuccess(const std::string& userExternalId, const std::string& endpointAccessToken) {
std::cout << "Attached to user" << std::endl;
}
void onAttachFailure() {
std::cout << "Failed to attach to user" << std::endl;
}
void onDetachSuccess(const std::string& endpointAccessToken) {
std::cout << "Detached from user" << std::endl;
}
void onDetachFailure() {
std::cout << "Failed to detach from user" << std::endl;
}
};
IEndpointAttachStatusListener listener = new DummyAttachNotificationListener();
Kaa::getKaaClient().getEndpointRegistrationManager().setAttachStatusListener(listener);
...

References