Providing values for Context properties

This library implements the provider side of the ContextKit's D-Bus protocol. It has both a C++ and a C interface, so you can choose which you prefer. For the documentation of the C API, see C Api.

The C++ interface consists mainly of the three classes: Service, Property, and Group in the namespace ContextProvider. They are declared in the ContextProvider header file.

Thus, you would typically gain access to the classes like this

  #include <ContextProvider>

  using namespace ContextProvider;

  Service myService (...);

If you prefer not to have generic names like "Service" in your code, you can of course skip the "using" declaration and refer to the classes as "ContextProvider::Service", etc. If that is too long, consider a namespace alias like this:

  #include <ContextProvider>

  namespace CP = ContextProvider;

  CP::Service myService (...);

The basic pattern to use this library is to create a Service instance to represent you on D-Bus and then to add Property instances to it for the keys that you want to provide. Once this is done, you can call Property::setValue() and Property::unsetValue() at any time to change the value of the property.

Communication with clients happens asynchronously and this library needs a running event loop for that.

Thus, a simple provider might look like this:

  #include <ContextProvider>

  using namespace ContextProvider;

  void main(int argc, char **argv)
  {
      QApplication app(argc, argv);

      Service myService(QDBusConnection::SessionBus, "com.example.simple");
      Property myProperty(myService, "Example.Simple");

      // set initial value of property
      myProperty.set(100);

      app.exec();
  }

If you need to know when someone actually subscribes to one of your properties, you can connect to the firstSubscriberAppeared and lastSubscriberDisappeared signals of the Property instances. You can also use a Group if you are only interested in whether at least one of a set of Property objects is subscribed to.

Valid property names

Context FW maintains a list of core properties. If you are providing a core property, you need to name it as it is described in the core property list (e.g., Screen.TopEdge).

If you want to provide a non-core property, its name must be a valid name for a D-Bus object path (e.g., /com/mycompany/screen/topedge). A valid D-Bus object path starts with / and contains zero or more elements separated by / . Each element must only contain the following characters: [A-Z][a-z][0-9]_