# BadgeCountSignaling

The BadgeCountSignaling library implements the handling of presence subscription calls sent to the AppService. This is used by the myApps client to display Badge Counts on the App Icon.

## Dependencies

  AppWebsocket
    The AppWebsocket library is used to receive the subscription calls as JSON signaling
  AppUpdates
    It is assumed that the Websocket Session uses the class AppUpdatesSession as base class so that this class can be used for the Websocket interface.

## File information

File | common/interface/stask.h
Classes | UBadgeCountSignaling BadgeCountSignaling BadgeCountCall BadgeCountPresenceMonitor

# Classes

## UBadgeCountSignaling

  This class must be allocated by the application, typically as base class to the instance class. The library uses the callback to allocate an appropriate instance when a presence subscription is received

    class UBadgeCountSignaling {

    public:
        virtual void CreateBadgeCountPresenceMonitor(class BadgeCountSignaling * signaling, int call, const char * user, const char * topic) = 0;
    };

virtual void CreateBadgeCountPresenceMonitor(class BadgeCountSignaling * signaling, int call, const char * user, const char * topic) = 0;
  In this call the application has to allocate a class which uses BadgeCountPresenceMonitor as base class, which will then handle the subscription call. For this the arguments signaling and call have to be used

user
  SIP uri of he originating user of the presence subscription
topic
  SIP URI used as destination for the presence subscription

## BadgeCountSignaling

  This class must be allocated by the application for each AppWebsocket session from the PBX, typically when the "PbxInfo" message is received, which identifies the session as a session from the PBX. This class then uses this session to establish a signaling registration at the PBX, to be able to receive the subscription calls.

    class BadgeCountSignaling : public JsonApi {
        const char * Name() { return "PbxSignal"; };
        void Message(class json_io & msg, word base, const char * mt, const char * src);
        void JsonApiConnectionClosed();

    public:
        BadgeCountSignaling(class UBadgeCountSignaling * user, class AppUpdatesSession * session);
        ~BadgeCountSignaling();
        int nextCall();

        class UBadgeCountSignaling * user;
        class AppUpdatesSession * session;
        class btree * calls;
        int call;
    };

## BadgeCountCall

  Internal class, used by the library to handle a single subscription call

    class BadgeCountCall : public btree {
        int btree_compare(void * key) { return (int)(intp)key - call; };
        int btree_compare(class btree * b) { return ((class BadgeCountCall *)b)->call - call; };
    public:
        BadgeCountCall(class BadgeCountSignaling * signaling, int call);
        virtual ~BadgeCountCall();

        virtual void Signaling(class json_io & msg, word base, const char * src, const char * type) = 0;

        void SendConn();
        void SendRel();

        class BadgeCountSignaling * signaling;
        int call;
        byte state;
    };

## BadgeCountPresenceMonitor

  This class has to be used as base class for a class allocated in the CreateBadgeCountPresenceMonitor callback.

    class BadgeCountPresenceMonitor : public BadgeCountCall {
        void Signaling(class json_io & msg, word base, const char * src, const char * type) override;

    public:
        BadgeCountPresenceMonitor(class BadgeCountSignaling * signaling, int call);
        ~BadgeCountPresenceMonitor();

        void SendBadge(ulong64 count);
    };

BadgeCountPresenceMonitor(class BadgeCountSignaling * signaling, int call)
  Constructor. signaling and call are the arguments from the CreateBadgeCountPresenceMonitor function call
void SendBadge(ulong64 count)
  Can be called to update a badge count. A typical implementation uses the AppUpdates library for these calls.