# pbx_admin.h

IPbxAdminApi is an interface, which provides administrative access to the PBX. It uses the Websocket/Json interface "PbxAdmin". To be able to use this interface inside an App Service, a Websocket connection from the PBX has to exist. For this connection access to the "PbxAdminApi" has to be granted

## File information

File | common/interface/pbx_admin.h
Classes | IPbxAdminApi UPbxMonitorAdminObject UPbxMonitorConfig

# Classes

## IPbxAdminApi

        class IPbxAdminApi : public UJsonApiContext {
        public:
        static class IPbxAdminApi * Create(const char * domain, const char * pbx);
        virtual ~IPbxAdminApi() {};

        virtual void SetPbx(const char * domain, const char * pbx) = 0;
        virtual void MonitorAdminObject(class UPbxMonitorAdminObject * monitor) = 0;
        virtual void MonitorConfig(class UPbxMonitorConfig * monitor) = 0;
        virtual void SendGetConfigObjects() = 0;
        virtual void SendGetObject(const char * cn, const char* templt = NULL) = 0;
        virtual void SendUpdateObject(class json_io& msg, char* buffer, word base) = 0;
        virtual void SendGetNodes(ulong64 limit, const char* last) = 0;
        virtual void SendGetStun() = 0;
        virtual void SendGetBooleans(ulong64 limit, const char* last) = 0;
        virtual void SendTestFilter(const char* sip, int num) = 0;
        };

This is the interface class which provides the public functions for the features of the interface after initialization is done.

### Public functions

Create

This functions needs to be called as part of the initialization to create the interface class.

Parameters

  char * domain | The name of the domain, to be used for the Api
  char * pbx | The name of the pbx, to be used for the Api

Return value
  Returns the pointer to the IPbxAdmin class

For this to work, the AppInstance class needs to use JsonApiContext as base class.

    class <Your App Name> : public AppInstance, ... , public JsonApiContext

After the Create function the interface has to be registered in the JsonApiContext

    pbxAdminApi = IPbxAdminApi::Create(domain, pbx);
    RegisterJsonApi(pbxAdminApi);

MonitorAdminObject

Starts monitoring of the PBX Admin object. The UPbxMonitorAdminObject virtual functions are called on changes

Parameters

  class UPbxMonitorAdminObject * monitor | The virtual class for the callback functions

Use UPbxMonitorAdminObject as a base class of one of your classes and call this function to start monitoring. Example:

    class <Your App Name> : public AppInstance, ... , public UPbxMonitorAdminObject {
        ...
        pbxAdminApi->MonitorAdminObject(this);
    }

MonitorConfig

Starts monitoring of the PBX for some basic config changes

Parameters

  class UPbxMonitorConfig * monitor | The virtual class for the callback functions

Use UPbxMonitorConfig as a base class of one of your classes and call this function to start monitoring. Example:

    class <Your App Name> : public AppInstance, ... , public UPbxMonitorConfig {
        ...
        pbxAdminApi->MonitorConfig(this);
    }

SendGetConfigObjects

Requests a list of all the Config Templates

Use SendGetConfigObjects to requests a list of all the Config Templates to the PBX. Example:

    pbxAdminApi->SendGetConfigObjects();

SendGetObject

Requests a PBX object data

Parameters

  const char* cn | The common name of the requested PBX OBject

  const char* templt | Defines if the information is generated with the information from config templates or without. Default is, that the information is generated without the information from the templates. The values can be "with", "without" or not be present at all.

Use SendGetObject to requests a PBX object data to the PBX. Example:

    pbxAdminApi->SendGetObject("User0");

SendUpdateObject

Requests a PBX object data

Parameters

  class json_io& msg |
  char* buffer |
  word base |

Use SendUpdateObject to update a PBX object data to the PBX. Example:

    char buffer[1024];
    json_io msg(buffer);
    word base = msg.add_object(JSON_ID_ROOT, 0);
    msg.add_string(base, "h323", h323);
    msg.add_string(base, "cn", cn);
    msg.add_string(base, "guid", guid);
    pbxAdminApi->SendUpdateObject(msg, buffer, base);

SendGetNodes

Requests a list of all the nodes and locs

Parameters

  ulong64 limit | The max number of nodes returned (it cannot be higher than 200)
  const char* last | The name of the last node received (NULL if no nodes have been received yet)

Use SendGetNodes to requests a list of all the nodes and locs to the PBX. SendGetNodes must be called until an empty array is received. Example:

    pbxAdminApi->SendGetNodes(200, "NodeTest");

SendGetStun

Requests STUN and TURN information

Use SendGetStun to requests the STUN and TURN data. Example:

    pbxAdminApi->SendGetStun();

SendGetBooleans

Requests a list of all the boolean objects

Parameters

  ulong64 limit | The max number of booleans returned (it cannot be higher than 200)
  const char* last | The name of the last boolean object received (NULL if no objects have been received yet)

Use SendGetBooleans to requests a list of all the boolean objects to the PBX. SendGetBooleans must be called until an empty array is received. Example:

    pbxAdminApi->SendGetBooleans(200, "BoolTest");

SendTestFilter

Tests if a number can be set as call diversion

Parameters

  const char* sip | The user where the call diversion is added
  const char* num | The number that the user wants to set on the call diversion

Example:

    pbxAdminApi->SendTestFilter("atlantis", "200");

## UPbxMonitorAdminObject

    class UPbxMonitorAdminObject {
    public:
        virtual void PbxAdminObjectUpdate(const char * pwd, const char * key) = 0;
    };

Virtual base class to be used for the callback on Admin object changes

## UPbxMonitorConfig

    class UPbxMonitorConfig {
    public:
        virtual void PbxConfigUpdate(const char * domain, const char * pbx, const char * dns, bool gk_domain) = 0;
    };

Virtual base class to be used for the callback on PBX config changes