int main(int argc, char ** argv) { SubscriptionManager sm; SDMSubreqst sub_msg; SDMSerreqst ser_msg; SDMDeletesub del_msg; sub_msg.msg_id.setInterface(1); sub_msg.msg_id.setMessage(2); sub_msg.destination.setAddress(inet_addr("127.0.0.1")); sub_msg.destination.setPort(4050); sm.AddSubscription(sub_msg) ? printf("First added\n") : printf("First not added\n"); sm.AddSubscription(sub_msg) ? printf("Second added\n") : printf("Second not added\n"); ser_msg.reply_id.setInterface(1); ser_msg.reply_id.setMessage(3); sub_msg.destination.setAddress(inet_addr("127.0.0.1")); sub_msg.destination.setPort(4050); sm.AddSubscription(ser_msg) ? printf("Third added\n") : printf("Third not added\n"); sub_msg.destination.setPort(4051); sm.AddSubscription(ser_msg) ? printf("Fourth added\n") : printf("Fourth not added\n"); sm.Publish(1,3,"A",1); return 0; }
void* Publisher(void * args) { int published = 0; short data; while(1) { data = (short)(rand()&0x00FF); pthread_mutex_lock(&subscription_mutex); if (subscriptions.Publish(1,1,(char*)&data,2)) { published++; } pthread_mutex_unlock(&subscription_mutex); printf("Produced %d\tPublished %d\n",data,published); sleep(1); } return NULL; }
void* Publisher(void * args) { int published = 0; short data; while(published < 10) { data = (short)(rand()&0x00FF); char bufdata[2]; PUT_SHORT(bufdata, data); pthread_mutex_lock(&subscription_mutex); if (subscriptions.Publish(1,1,bufdata,2)) { published++; } pthread_mutex_unlock(&subscription_mutex); printf("Produced %d\tPublished %d / 10\n",data,published); sleep(1); } return NULL; }