This interface is used for internal modules of the myApps launcher. It is not needed by app developers.
The ApiWebsocketClient connects to an ApiRelay instance that is usually also a local service. It allows implementing API providers and API consumers that can interact with the apps running in myApps. The websocket protocol is used for the connection.
File | common/lib/apiwebsocket_client.h |
Classes |
ApiWebsocketClient ApiProvider ApiConsumer |
class ApiWebsocketClient : public UWebsocketClient, public UTimer {
...
public:
ApiWebsocketClient(class IIoMux * const iomux, class ISocketProvider * const tcp, class ISocketProvider * const tls, class IDns * const dns, class IInstanceLog * const log, const char * uri, const char * pwd, const char * dn);
virtual ~ApiWebsocketClient();
bool ApiWebsocketClientIsConnected();
void ApiWebsocketClientClose();
virtual void ApiWebsocketClientCloseComplete() = 0;
virtual void ApiWebsocketClientConnected() {};
virtual void ApiWebsocketClientDisconnected() {};
};
Base class for websocket sessions to the ApiRelay of the myApps launcher.
Contructor function.
const char * uri | The websocket URI of the api relay service. |
const char * pwd | The password for authenticating to the api relay service. |
const char * dn | The display name that shall be used for API providers. |
Shall be called to close the connection and all attached API providers and consumers.
The application will get the ApiWebsocketClientCloseComplete
callback
when this is done.
Will be called after the connection and all attached API providers and consumers have been closed. Applications that use the library should not exit before this callback is received.
Called if the connection went up.
Called if the connection went down.
class ApiProvider : public btree, public UIoExec {
...
protected:
void ApiProviderClosed();
...
public:
ApiProvider(class ApiWebsocketClient * const client, const char * api);
void ApiProviderSend(const char * client, const char * consumer, const char * src, class json_io & msg, word base, char * buffer);
void ApiProviderUpdate(class json_io & json, word base, char * buffer);
virtual void ApiProviderRecv(const char * client, const char * consumer, const char * src, class json_io & msg, word base) = 0;
virtual void ApiProviderConsumerClosed(const char * client, const char * consumer) {}
virtual void ApiProviderClose() { ApiProviderClosed(); }
virtual void ApiProviderConnected() {}
virtual void ApiProviderDisconnected() {}
};
Base class for client API providers. An ApiProvider is attached during creation to an ApiWebsocketClient. It is deleted by the ApiWebsocketClient. So the application doesn't need to keep a reference to it.
Contructor function.
class ApiWebsocketClient * const client | The ApiWebsocketClient instance to be used by the provider. |
const char * api | The name of the API that is implemented by this class (e.g. com.innovaphone.search). |
This function is used for sending ApiResult messages.
The parameters client, consumer and src should be echoed from the corresponding ApiRequest message received using ApiProviderRecv
.
const char * client | The opaque client ID from the API request. |
const char * consumer | The opaque consumer ID from the API request. |
const char * src | The opaque source ID from the API request. |
class json_io & msg | A JSON structure containing an API request. |
word base | The reference pointing to the base of the message inside the JSON structure. |
char * buffer | A buffer that is big enough to contain the whole encoded message. |
This function is used for sending a new ApiModel to the client.
class json_io & msg | A JSON structure containing the new API model. |
word base | The reference pointing to the base of the message inside the JSON structure. |
char * buffer | A buffer that is big enough to contain the whole encoded message. |
This callback is called when an ApiRequest is received. ApiResults should be sent using the ApiProviderSend
function.
The extra parameters (client, consumer and src) must be echoed back in the response.
const char * client | The opaque client ID. Must be echoed back in the API response. |
const char * consumer | The opaque consumer ID. Must be echoed back in the API response. |
const char * src | The opaque source ID chosen be the consumer. Must be echoed back in the API response. |
class json_io & msg | A JSON structure containing an API request. |
word base | The reference pointing to the base of the message inside the JSON structure. |
This callback is called when an API consumer has been closed. This can be used to cancel any open API requests or subscriptions done by that consumer.
const char * client | The ID of the client. |
const char * consumer | The ID of the consumer. |
This callback is called before the object is deleted by the AppWebsocketClient.
Subclasses should stop any activities and then call ApiProviderClosed()
.
Called when the provider is connected to the api relay.
Called when the provider is disconnected from the api relay.
This function should be called after the ApiProviderClose()
callback, when the implementing class has stopped any activities.
class ApiConsumer : public btree, public UIoExec {
....
protected:
void ApiConsumerClosed();
...
public:
ApiConsumer(class ApiWebsocketClient * const client, const char * api);
void ApiConsumerSend(const char * provider, const char * src, class json_io & msg, word base, char * buffer);
virtual void ApiConsumerRecv(const char * provider, const char * src, class json_io & msg, word base) {};
virtual void ApiConsumerUpdate(class json_io & model, word base) {};
virtual void ApiConsumerClose() { ApiConsumerClosed(); }
virtual void ApiConsumerConnected() {}
virtual void ApiConsumerDisconnected() {}
};
Base class for client API consumers. An ApiConsumer is attached during creation to an ApiWebsocketClient. It is deleted by the ApiWebsocketClient. So the application doesn't need to keep a reference to it.
Contructor function.
class ApiWebsocketClient * const client | The ApiWebsocketClient instance to be used by the consumer. |
const char * api | The name of the API that is used by this class (e.g. com.innovaphone.search). |
Call this function to send an ApiRequst message to the specified provider.
const char * provider |
Can be one of the following:
|
const char * src | An optional source ID that shall be mirrored back in the API result. |
class json_io & msg | A JSON structure containing an API request. |
word base | The reference pointing to the base of the message inside the JSON structure. |
char * buffer | A buffer that is big enough to contain the whole encoded message. |
This function is called when an ApiResult message is received.
const char * provider | The provider ID. |
const char * src | The source ID that was sent with the corresponding API request. |
class json_io & msg | A JSON structure containing an API result. |
word base | The reference pointing to the base of the message inside the JSON structure. |
This function is called when the API model has changed.
class json_io & msg | A JSON structure containing the new API model. |
word base | The reference pointing to the base of the message inside the JSON structure. |
This callback is called before the object is deleted by the AppWebsocketClient.
Subclasses should stop any activities and then call ApiConsumerClosed()
.
Called when the consumer is connected to the api relay.
Called when the consumer is disconnected from the api relay.
This function should be called after the ApiConsumerClose()
callback, when the implementing class has stopped any activities.