main() { lbm_context_t *ctx; /* pointer to context object */ lbm_context_attr_t * cattr; /* pointer to context attribute object */ int err; /* return status of lbm functions (true=error) */ #if defined(_WIN32) HANDLE wthrdh; #else pthread_t pthids; #endif /* _WIN32 */ #if defined(_MSC_VER) /* windows-specific code */ WSADATA wsadata; int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); if (wsStat != 0) { printf("line %d: wsStat=%d\n",__LINE__,wsStat); exit(1); } #endif if (lbm_context_attr_create(&cattr) != 0) { fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); exit(1); } /* Setting the resolver address using the string method */ if (lbm_context_attr_str_setopt(cattr, "operational_mode", "sequential") != 0) { fprintf(stderr, "lbm_context_attr_str_setopt:operational_mode: %s\n", lbm_errmsg()); exit(1); } err = lbm_context_create(&ctx, cattr, NULL, NULL); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } #if defined(_WIN32) if ((wthrdh = CreateThread(NULL, 0, seq_thread, ctx, 0, NULL)) == NULL) { fprintf(stderr, "could not create thread\n"); exit(1); } #else if (pthread_create(&pthids, NULL, seq_thread, ctx) != 0) { fprintf(stderr, "could not spawn thread\n"); exit(1); } #endif /* _WIN32 */ /* Wait forever */ while (1) { } }
void *seq_thread(void *arg) #endif /* _WIN32 */ { lbm_context_t *ctx = (lbm_context_t *) arg; while (1) { if (lbm_context_process_events(ctx, 500) == -1) { printf("ERROR processing context events: %s\n", lbm_errmsg()); exit(1); } } }
main() { lbm_context_t *ctx; /* pointer to context object */ lbm_topic_t *topic_1; /* pointer to topic object */ lbm_src_t *src; /* pointer to source object */ lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ lbm_context_attr_t * cattr; /* pointer to context attribute object */ int err; /* return status of lbm functions (true=error) */ lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ #if defined(_MSC_VER) /* windows-specific code */ WSADATA wsadata; int wsStat = WSAStartup(MAKEWORD(2, 2), &wsadata); if (wsStat != 0) { printf("line %d: wsStat=%d\n", __LINE__, wsStat); exit(1); } #endif /* Initialize the defaults for the context attribute object */ if (lbm_context_attr_create(&cattr) != 0) { fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); exit(1); } /* Creating the context */ err = lbm_context_create(&ctx, cattr, NULL, NULL); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Delete the context attribute object */ lbm_context_attr_delete(cattr); /* Initializing the source attribute object */ if (lbm_src_topic_attr_create(&tattr) != 0) { fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); exit(1); } /* Allocating the topic */ err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic", tattr); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Create an event queue and associate it with a callback */ if (lbm_event_queue_create(&evq, NULL, NULL, NULL) == LBM_FAILURE) { fprintf(stderr, "lbm_event_queue_create: %s\n", lbm_errmsg()); exit(1); } /* Creating the source */ err = lbm_src_create(&src, ctx, topic_1, handle_src_event, NULL, evq); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* This runs the eventQ for 10 seconds. This means for the next 10 seconds */ /* all of the sources events will be processed on this thread. */ if(lbm_event_dispatch(evq, 10000) == LBM_FAILURE) { fprintf(stderr, "lbm_event_dispatch returned error: %s\n", lbm_errmsg()); } /* Delete the first and second source topic attribute objects */ lbm_src_topic_attr_delete(tattr); /* Finished with all LBM functions, delete the source and context object. */ lbm_src_delete(src); lbm_context_delete(ctx); lbm_event_queue_delete(evq); #if defined(_MSC_VER) WSACleanup(); #endif }
main() { lbm_context_t *ctx; /* pointer to context object */ lbm_topic_t *topic_1; /* pointer to topic object */ lbm_topic_t *topic_2; /* pointer to topic object */ lbm_src_t *src_1; /* pointer to source object */ lbm_src_t *src_2; /* pointer to source object */ lbm_src_topic_attr_t *tattr_1; /* pointer to source attribute object */ lbm_src_topic_attr_t *tattr_2; /* pointer to source attribute object */ lbm_context_attr_t * cattr; /* pointer to context attribute object */ lbm_uint16_t res_port; /* Int to set resolver port */ lbm_uint16_t des_port; /* Int to set lbtrm destination port */ int err; /* return status of lbm functions (true=error) */ #if defined(_MSC_VER) /* windows-specific code */ WSADATA wsadata; int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); if (wsStat != 0) { printf("line %d: wsStat=%d\n",__LINE__,wsStat); exit(1); } #endif /* Initialize the defaults for the context attribute object */ if (lbm_context_attr_create(&cattr) != 0) { fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); exit(1); } /* Setting the resolver address using the string method */ if (lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12") != 0) { fprintf(stderr, "lbm_context_attr_str_setopt:resolver_multicast_address: %s\n", lbm_errmsg()); exit(1); } /* Setting the resolver port using the data-type value method */ res_port = 12345; if (lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)) != 0 ) { fprintf(stderr, "lbm_context_attr_setopt:resolver_mutlicast_port: %s\n", lbm_errmsg()); exit(1); } /* Creating the context */ err = lbm_context_create(&ctx, cattr, NULL, NULL); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Delete the context attribute object */ lbm_context_attr_delete(cattr); /* Initializing the source attribute object */ if (lbm_src_topic_attr_create(&tattr_1) != 0) { fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); exit(1); } /* Setting the transport via the source topic string method */ if (lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm") != 0 ) { fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); exit(1); } /* Setting the lbtrm destination port via the direct value set method */ des_port = 14001; if (lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)) != 0 ) { fprintf(stderr, "lbm_src_topic_attr_setopt:transport_lbtrm_destination_port: %s\n", lbm_errmsg()); exit(1); } /* Allocating the topic */ err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Creating the source */ err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Initialized the second source attributes as a copy of the first */ if (lbm_src_topic_attr_dup(&tattr_2, tattr_1) != 0 ) { fprintf(stderr, "lbm_src_topic_attr_dup: %s\n", lbm_errmsg()); exit(1); } /* Now modify the destination port for this second source to put the publisher on a different transport */ des_port = 14002; if (lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)) != 0 ) { fprintf(stderr, "lbm_src_topic_attr_setopt:transport_lbtrm_destination_port: %s\n", lbm_errmsg()); exit(1); } /* Allocating the second topic */ err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Creating the source */ err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); if (err) { printf("line %d: %s\n", __LINE__, lbm_errmsg()); exit(1); } /* Delete the first and second source topic attribute objects */ lbm_src_topic_attr_delete(tattr_1); lbm_src_topic_attr_delete(tattr_2); /* Finished with all LBM functions, delete the source and context object. */ lbm_src_delete(src_1); lbm_src_delete(src_2); lbm_context_delete(ctx); #if defined(_MSC_VER) WSACleanup(); #endif }