client-cpp  0.6.3
Profile management

Profile subsystem is based on auto-generated class(es) according to the profile schema used during sdk generation.

Assume a profile schema has the following form:

{
"name": "Profile",
"namespace": "org.kaaproject.kaa.client.example",
"type": "record",
"fields": [
{
"name": "data",
"type": "string"
}
]
}

After calling avrogen.sh script Avro C++ compiler will be generated appropriate code and put it into ProfileGen.hpp header. So auto-generated notification class will be like:

struct Profile {
std::string data;
};

Below is an example of a profile container for C++:

#include "kaa/Kaa.hpp"
#include "kaa/gen/ProfileGen.hpp" // auto-generated header
using namespace kaa;
// Profile container based on AbstractProfileContainer class that is provided by the sdk
class BasicProfileContainer : public AbstractProfileContainer<Profile> {
public:
BasicProfileContainer(const Profile &profile) : profile_(profile) { }
virtual Profile getProfile() {
return profile_;
}
virtual void changeProfile(const Profile &profile) {
profile_ = profile;
// Update method should be called to notify about changes in the profile.
updateProfile();
}
private:
Profile profile_;
};
// Kaa client initialization based on BasicProfileContainer
void init(){
//Create client for Kaa SDK
//Sample profile
Profile profile;
profile.data = "some useful data";
//Create instance of profile container
ProfileContainerPtr container(new BasicProfileContainer(profile));
//Set simple profile container to profile manager.
//Starts Kaa
}