|
PreCache NetInjector Documentation Center : PreCache NetInjector Application Development Common Cases, Subscription C |
|
|
|
Common Cases, subscription code C the complete subscription code The previous code samples presented a simple publish/subscribe application. In this tutorial, we have learned how to enhance subscriptions by
#include <stdio.h> #include "PC_utl_log.h" #include "PC_evn_filter.h" #include "PC_evn_proxy.h" #include "PC_evn_notification.h" //Define a callback function. void notify1( { PC_STRING message; PC_STRING username; PC_CHAR *gender; PC_LONG *age; PC_UINT size; //Retrieve the values of predefined attributes. PC_evn_get_predefined_attr_by_name( PC_evn_get_predefined_attr_by_name( PC_STRING_TYPE,&size); PC_evn_get_predefined_attr_by_name( PC_evn_get_predefined_attr_by_name( PC_CHAR_TYPE,&size); //Build the notification. printf("Incoming notification for printf("From:\n"); printf("Name = %s\n",username); printf("Age = %d\n",(int)*age); if ((*gender == 'M')||(*gender=='m')) printf("Male\n") ; else if ((*gender == 'F')||(*gender=='f')) printf("Female\n"); }; //Define a callback function which can retrieve a void notify2( { PC_STRING message; PC_STRING username; PC_CHAR *gender; PC_LONG *age; PC_UINT size; PC_TypeCode typecode; PC_STRING interest; //Retrieve the value of the predefined attributes. PC_evn_get_predefined_attr_by_name( PC_STRING_TYPE,&size); PC_evn_get_predefined_attr_by_name( PC_STRING_TYPE,&size); PC_evn_get_predefined_attr_by_name( PC_LONG_TYPE,&size); PC_evn_get_predefined_attr_by_name( PC_CHAR_TYPE,&size); //Retrieve the value of the discretionary attribute. PC_evn_get_discretionary_attr( //Build the notification. printf("Incoming notification for printf("From:\n"); printf("Name = %s\n",username); printf("Age = %d\n",(int)*age); if ((*gender == 'M')||(*gender=='m')) printf("Male\n") ; else if ((*gender == 'F')||(*gender=='f')) printf("Female\n"); printf("Interest = %s\n\n",interest); }; int main(int argc, char* argv[]) { PC_Status nStatus; PC_evn_Proxy p; PC_evn_Subscription_Handle //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; }
//Submit the subscription. nStatus = PC_evn_subscribe_with_exp( "UserName==\"Jane\"UserName==\"Jane\"", if (nStatus != PC_SUCCESS) { printf("Subscription submission has failed\n"); return 0; } nStatus = PC_evn_subscribe_with_exp( if (nStatus != PC_SUCCESS) { printf("Subscription submission has failed return 0; } nStatus = PC_evn_subscribe_with_exp( if (nStatus != PC_SUCCESS) { printf("Subscription submission has failed return 0; } printf("Subscription was submitted... sleep(30); } |
|