Please Wait

Loading..

Posix C++ SDK 1.0.0

Create amazing realtime applications easily with Yalgaar Posix C++ SDK

1 Connect To Yalgaar

Notes:

This Yalgaar Posix C++ SDK is compatible with mosquitto 1.4.5 or above versions.

Current version does not support AES Encryption feature.

Download package and include "yalgaar_api.h" in your code.

#include "yalgaar_api.h"

To connect to a Yalgaar client, use following method, it must have valid Client Key.

yalgaar_connect(const char *clientKey,const char *uuid ,unsigned char isSecure,char *aesSecretkey,unsigned int aesType, void(*connectionCallback)( int,char * ));

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: const char *
  • uuid
    • Description: Any unique user name for user to enable presence feature for client. UUID is CASE SENSITIVE and only alpha numeric, hyphens,@,underscore allowed and maximum length must be 50.
    • DataType: unsinged char
  • isSecure
    • Description: Specified connection is establish with SSL or not.
    • DataType: boolean (value must be true or false)
  • aesSecretkey
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: unsigned char
  • aesType
    • Description: Type of AES algorithm use for encrypt/decrypt message. Support AES type 128,192 and 256.
    • DataType: unsigned int
  • connectionCallback
    • Description: Called when successfully connected to server or any error during connection.
    • DataType: ENUM (yalgaar_error_t)


2 Publish Message

To publish message, use following method.

yalgaar_publish(const unsigned char *channel,char *message);

Parameter:

  • channel
    • Description: Channel name to be publish message. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • message
    • Description: Data to be send on given channel.
    • DataType: unsigned char


3 Subscribe Message

To subscribe message, use following method.

yalgaar_subscribe(uint8_t * channel,void(* subscribeMessageCallback)(void  *),void(*presenceMessageCallback)(char *), void(*errorMessageCallback)(void *));
yalgaar_subscribes(char **channel,void(* subscribeMessageCallback)(char *),void(*presenceMessageCallback)(char *), void(*errorMessageCallback)(char *));

Parameter:

  • channel
    • Description: channel name on which message will be subscribed. For multiple channel names use "yalgaar_subscribes" function. Channel name is CASE SENSITIVE. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • subscribeMessageCallback
    • Description: Callback function to consume received message.
    • DataType: char *
  • presenceMessageCallback
    • Description: Callback function to consume presence events such as join or leave.
    • DataType: struct presence_t *
  • errorMessageCallback
    • Description: Callback is called on system error occurred during subscription.
    • DataType: char *


4 Unsubscribe Message

To unsubscribe message, use following method.

yalgaar_unsubscribe(char *channel);
  • channel
    • Description: Channel name to be unsubscribe. Channel name is CASE SENSITIVE. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char


5 Get User List

To get list of all user subscribe with specified channel name, use following method.

yalgaar_GetUserList(char *channelName,void(* userListCallback)(char *),void(*errorMessageCallback)(void *));

Parameter:

  • channelName
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • userListCallback
    • Description: Callback is called when successfully get user list.
    • DataType: char *
  • errorMessageCallback
    • Description: Callback is called on system error occurred during getting user list.
    • DataType: void *


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

yalgaar_GetChannelList(char *UUID,void(* channelListCallback)(char *),void(*errorMessageCallbacks)(char *));

Parameter:

  • UUID
    • Description: Any unique user name or user id. UUID is CASE SENSITIVE and only alpha numeric, hyphens,@,underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • channelListCallback
    • Description: Callback is called when successfully get channel list.
    • DataType: char *
  • errorMessageCallbacks
    • Description: Callback is called on system error occurred during getting channel list.
    • DataType: void *


7 History Message

To get message history from specified channel name, use following method.

yalgaar_GetHistoryMessage(char *channelName, unsigned char msg_count,void(* historymessagecallback)(char *),void(*errorMessageCallback)(char *));

Parameter:

  • channelName
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • messageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • DataType: unsigned char
  • historymessagecallback
    • Description: Callback is called when successfully get history message list.
    • DataType: char *
  • errorMessageCallbacks
    • Description: Callback is called on system error occurred during getting history message.
    • DataType: void *


8 Disconnect

To disconnect connection with YalgaarClient, use following method.

yalgaar_disconnect(void);


You can publish/subscribe message like so :

#include "yalgaar_api.h"
int pub_count = 1;
unsigned char ret = FAILURE;
char err_string[YALGAAR_ERROR_MESSAGE_LENGTH] = { '\0' };
unsigned char connection_connected = 0;
class yalgaar *objyalgaar;
void subscribe_message_callback(char *payload)
{
	printf("\n MSG:- %s\n", payload);
}
void presence_message_callback(char *message)
{
	printf("\npresence_message_callback:- %s\n", message);
}
void error_message_callback(char *error)
{
	printf("\nError:- %s\n", error);
}
void connection_Callback(int result, char* error_msg)
{
	if (!result)
	{
		ret = objyalgaar->yalgaar_subscribe("YourChannel", subscribe_message_callback, presence_message_callback, error_message_callback);
		if (SUCCESS != ret)
		{
			objyalgaar->enum_to_message(ret, err_string);
			printf("\nError: %s", err_string);
		}
		connection_connected = 1;
	}
	else
	{
		printf("\nError : %s", error_msg); fflush(stdout);
	}
}
int main() {
	int x = 5;
	printf("X: %02u \n\n\n\n", x);
	objyalgaar = yalgaar_connect(YALGAAR_CLIENT_KEY, "UUID", 1, 0, 0, connection_Callback);
	while (1)
	{
		if (connection_connected == 1)
		{
			if (pub_count)
			{
				ret = objyalgaar->yalgaar_publish("YourChannel", "This is Yalgaar Posix C++ SDK Example");
				if (SUCCESS != ret)
				{
					objyalgaar->enum_to_message(ret, err_string);
					printf("\n ERR:- %s", err_string);
				}
				pub_count--;
			}
		}
		objyalgaar->yalgaar_loop();
	}
	return 0;
}