PreCache NetInjector Documentation Center : PreCache NetInjector Application Development

Common Cases, Publication — C

   







Common Cases, publication code — C

— the full code sample for the Common Cases tutorial


The sample for this tutorial presented more examples of setting attributes. While the process of the publication is the same as in Basic Case, Publication — C, we have added statements for

#include <stdio.h>

#include "PC_utl_log.h"

#include "PC_evn_filter.h"

#include "PC_evn_proxy.h"

#include "PC_evn_notification.h"

main(int argc, char* argv[])

{

      PC_Status Status;

      PC_evn_Proxy p;

      PC_evn_Notification n1,n2;

      PC_LONG age;

      PC_CHAR gender;

//Create a proxy for the channel and client.

      nStatus = PC_evn_create_proxy(&p,40,3001);

      

      if (nStatus != PC_SUCCESS)      

      {

            printf("Proxy creation has failed\n");

            return 0;

      }

//Create a notification.

      nStatus = PC_evn_create_notification(
            &n1,
            p
            "Sample.Chat",NULL);

      if (nStatus != PC_SUCCESS)

      {

            printf("Notification creation has failed
                  \n");

            return 0;

      }

//Set the values for predefined attributes.

      PC_evn_set_predefined_attr_by_name(
            n1,"Message",
            "Make this world a better place!",
            PC_STRING_TYPE,
            strlen("Make this world a better place!"));

            PC_evn_set_predefined_attr_by_name(
            n1,
            "UserName",
            "Jane",
            PC_STRING_TYPE,
            strlen("Jane"));

      age = 10;

      PC_evn_set_predefined_attr_by_name(
            n1,
            "Age",

            &age,PC_LONG_TYPE,0);

      gender = 'F';

      PC_evn_set_predefined_attr_by_name(
            n1,
            "Gender",

            &gender,
            PC_CHAR_TYPE,0);

//Publish the notification.

      nStatus = PC_evn_publish(p,n1);

      if (nStatus != PC_SUCCESS)

      {

            printf("Failed to publish notification
                  \n");

            return 0;

      }

//Create a second notification.

      nStatus = PC_evn_create_notification(
            &n2,
            p,
            "Sample.Chat",NULL);

      if (nStatus != PC_SUCCESS)

      {

            printf("Notification creation has failed
                  \n");

            return 0;

      }

//Set the values for predefined attributes.

      PC_evn_set_predefined_attr_by_name(
            n2,"Message",

            "Dolly Parton, I love you!",

             PC_STRING_TYPE,

            strlen("Dolly Parton, I love you!"));

      PC_evn_set_predefined_attr_by_name(
            n2,"UserName",

            "Laurel",

            PC_STRING_TYPE,

            strlen("Laurel"));

      age = 12;

      PC_evn_set_predefined_attr_by_name(
            n2,"Age",&age,

            PC_LONG_TYPE,0);

      gender = 'f';

      PC_evn_set_predefined_attr_by_name(
            n2,"Gender",&gender,

            PC_CHAR_TYPE,0);

//Set a discretionary attribute's value.

      PC_evn_add_discretionary_attr(
            n2,"Interest","Country Music",

            PC_STRING_TYPE,strlen("Country Music"));

      

//Publish the second notification.

      nStatus = PC_evn_publish(p,n2);

      if (nStatus != PC_SUCCESS)

      {

            printf("Failed to publish notification
                  \n");

            return 0;

      }

}

In the final tutorial chapter, Common Cases, Subscription — C, we will build the participating subscriber's application.