int OSPL_MAIN (int argc, char *argv[]) { DDS_Subscriber QueryConditionDataSubscriber; DDS_DataReader QueryConditionDataDataReader; StockMarket_Stock* QueryConditionDataSample; DDS_sequence_StockMarket_Stock* msgList = DDS_sequence_StockMarket_Stock__alloc(); DDS_SampleInfoSeq* infoSeq = DDS_SampleInfoSeq__alloc(); c_bool isClosed = FALSE; unsigned long j; DDS_char* QueryConditionDataToSubscribe; DDS_char *query_string = "ticker=%0"; DDS_QueryCondition queryCondition; os_time delay_200ms = { 0, 200000000 }; int count = 0; // usage : QueryConditionSubscriber <topic's content filtering string> if( argc < 2 ) { usage(); } printf("\n\n Starting QueryConditionSubscriber..."); printf("\n\n Parameter is \"%s\"", argv[1]); QueryConditionDataToSubscribe = argv[1]; createParticipant("QueryCondition example"); // Register Stock Topic's type in the DDS Domain. g_StockTypeSupport = (DDS_TypeSupport) StockMarket_StockTypeSupport__alloc(); checkHandle(g_StockTypeSupport, "StockMarket_StockTypeSupport__alloc"); registerStockType(g_StockTypeSupport); // Create Stock Topic in the DDS Domain. g_StockTypeName = StockMarket_StockTypeSupport_get_type_name(g_StockTypeSupport); g_StockTopic = createTopic("StockTrackerExclusive", g_StockTypeName); DDS_free(g_StockTypeName); DDS_free(g_StockTypeSupport); // Create the Subscriber's in the DDS Domain. QueryConditionDataSubscriber = createSubscriber(); // Request a Reader from the the Subscriber. QueryConditionDataDataReader = createDataReader(QueryConditionDataSubscriber, g_StockTopic); // Create QueryCondition printf( "\n=== [QueryConditionSubscriber] Query : ticker = %s\n", QueryConditionDataToSubscribe ); queryCondition = createQueryCondition(QueryConditionDataDataReader, query_string, (DDS_char*) QueryConditionDataToSubscribe); printf( "\n=== [QueryConditionSubscriber] Ready..." ); do { g_status = StockMarket_StockDataReader_take_w_condition(QueryConditionDataDataReader, msgList, infoSeq, DDS_LENGTH_UNLIMITED, queryCondition); checkStatus(g_status, "StockMarket_StockDataReaderView_take"); if( msgList->_length > 0 ) { j = 0; do { QueryConditionDataSample = &msgList->_buffer[j]; // When is this supposed to happen? // Needs comment... if( infoSeq->_buffer[j].valid_data ) { printf("\n\n %s: %f", QueryConditionDataSample->ticker, QueryConditionDataSample->price); if( QueryConditionDataSample->price == (DDS_float) -1.0f ) { printf("\n ===[QueryConditionSubscriber] QueryConditionDataSample->price == -1.0f "); isClosed = TRUE; } } } while( ++j < msgList->_length ); g_status = StockMarket_StockDataReader_return_loan(QueryConditionDataDataReader, msgList, infoSeq); checkStatus(g_status, "StockMarket_StockDataReaderView_return_loan"); } os_nanoSleep(delay_200ms); ++count; } while( isClosed == FALSE && count < 1500 ); printf("\n\n=== [QueryConditionSubscriber] Market Closed"); // Cleanup DDS from the created Entities. deleteQueryCondition(QueryConditionDataDataReader, queryCondition); deleteDataReader(QueryConditionDataSubscriber, QueryConditionDataDataReader); deleteSubscriber(QueryConditionDataSubscriber); deleteTopic(g_StockTopic); deleteParticipant(); // Cleanup C allocations, // recursively freeing the allocated structures and sequences using the OpenSplice API. DDS_free(msgList); DDS_free(infoSeq); // Print out an empty line, just to let behind a clean new line for the shell.. printf("\n\r"); return 0; }
int main(int argc, char *argv[]) { char* publisher_name; int i, sampleIndex, nb_iteration; c_bool isStoppingSubscriber; float price; char* geTicker = "GE"; int geTickerLength = strlen(geTicker); char* msftTicker = "MSFT"; int msftTickerLength = strlen(msftTicker); os_time os_delay100 = { 0, 100000000 }; os_time os_delay2000 = { 2, 0 }; DDS_Publisher QueryConditionDataPublisher; DDS_DataWriter QueryConditionDataDataWriter; QueryConditionData_Stock* geStockSample; QueryConditionData_Stock* msftStockSample; DDS_InstanceHandle_t geInstanceHandle; DDS_InstanceHandle_t msftInstancetHandle; createParticipant("QueryCondition example"); // Register Stock Topic's type in the DDS Domain. g_StockTypeSupport = (DDS_TypeSupport) QueryConditionData_StockTypeSupport__alloc(); checkHandle(g_StockTypeSupport, "QueryConditionData_StockTypeSupport__alloc"); registerStockType(g_StockTypeSupport); // Create Stock Topic in the DDS Domain. g_StockTypeName = (char*) QueryConditionData_StockTypeSupport_get_type_name(g_StockTypeSupport); g_StockTopic = createTopic("StockTrackerExclusive", g_StockTypeName); DDS_free(g_StockTypeName); DDS_free(g_StockTypeSupport); // Create the Publisher's in the DDS Domain. QueryConditionDataPublisher = createPublisher(); // Request a Writer from the the Publisher. QueryConditionDataDataWriter = createDataWriter(QueryConditionDataPublisher, g_StockTopic, FALSE); // Publish a Stock Sample reflecting the state of the Msg DataWriter. geStockSample = QueryConditionData_Stock__alloc(); msftStockSample = QueryConditionData_Stock__alloc(); msftStockSample->ticker = DDS_string_alloc(msftTickerLength); snprintf(msftStockSample->ticker, msftTickerLength + 1, "%s", msftTicker); msftStockSample->price = 12.00f; geStockSample->ticker = DDS_string_alloc(geTickerLength); snprintf(geStockSample->ticker, geTickerLength + 1, "%s", geTicker); geStockSample->price = 25.00f; geInstanceHandle = QueryConditionData_StockDataWriter_register_instance(QueryConditionDataDataWriter, geStockSample); msftInstancetHandle = QueryConditionData_StockDataWriter_register_instance(QueryConditionDataDataWriter, msftStockSample); nb_iteration = 20; // The subscriber should display the prices sent by the publisher with the highest ownership strength for( sampleIndex = 0; sampleIndex < nb_iteration ; ++sampleIndex ) { printf("GE : %.1f MSFT : %.1f\n", geStockSample->price, msftStockSample->price); writeStockSample(QueryConditionDataDataWriter, geInstanceHandle, geStockSample); writeStockSample(QueryConditionDataDataWriter, msftInstancetHandle, msftStockSample); geStockSample->price += 0.5; msftStockSample->price += 1.5; os_nanoSleep(os_delay100); } // This special price gives the end signal to the Subscriber: // signal to terminate geStockSample->price = -1.0f; msftStockSample->price = -1.0f; writeStockSample(QueryConditionDataDataWriter, geInstanceHandle, geStockSample); writeStockSample(QueryConditionDataDataWriter, msftInstancetHandle, msftStockSample); // This to make sure the Subscriber will get all the Samples. os_nanoSleep(os_delay2000); printf("Market Closed"); QueryConditionData_StockDataWriter_unregister_instance (QueryConditionDataDataWriter, geStockSample, geInstanceHandle); QueryConditionData_StockDataWriter_unregister_instance (QueryConditionDataDataWriter, msftStockSample, msftInstancetHandle); // Cleanup DDS from the created Entities. deleteDataWriter(QueryConditionDataPublisher, QueryConditionDataDataWriter); deletePublisher(QueryConditionDataPublisher); deleteTopic(g_StockTopic); deleteParticipant(); // Cleanup C allocations, // recursively freeing the allocated structures and sequences using the OpenSplice API. DDS_free(geStockSample); DDS_free(msftStockSample); // Print out an empty line, just to let behind a clean new line for the shell.. printf("\n\r"); return 0; }
int OSPL_MAIN (int argc, char *argv[]) { char* publisher_name; int i, sampleIndex, ownership_strength, nb_iteration; c_bool isStoppingSubscriber; float price; os_time os_delay200 = { 0, 200000000 }; os_time os_delay2000 = { 2, 0 }; DDS_Publisher OwnershipDataPublisher; DDS_DataWriter OwnershipDataDataWriter; OwnershipData_Stock* OwnershipDataSample; DDS_InstanceHandle_t userHandle; const char ticker [] = "MSFT"; DDS_unsigned_long stringLength = sizeof(ticker) - 1; // usage : Publisher.exe <publisher_name> <ownership_strength> <nb_iterations> if( argc < 5 ) { usage(); } printf("\n\n Starting OwnershipDataPublisher..."); printf("\n\n Parameters are:"); for( i = 1; i < argc ; ++i ) { printf("\n %d: %s", i, argv[i]); } publisher_name = argv[1]; ownership_strength = atoi(argv[2]); nb_iteration = atoi(argv[3]); isStoppingSubscriber = argv[4][0] == '1' ? TRUE : FALSE; createParticipant("Ownership example"); // Register Stock Topic's type in the DDS Domain. g_StockTypeSupport = (DDS_TypeSupport) OwnershipData_StockTypeSupport__alloc(); checkHandle(g_StockTypeSupport, "OwnershipData_StockTypeSupport__alloc"); registerStockType(g_StockTypeSupport); // Create Stock Topic in the DDS Domain. g_StockTypeName = OwnershipData_StockTypeSupport_get_type_name(g_StockTypeSupport); g_StockTopic = createTopic("StockTrackerExclusive", g_StockTypeName); DDS_free(g_StockTypeName); DDS_free(g_StockTypeSupport); // Create the Publisher's in the DDS Domain. OwnershipDataPublisher = createPublisher(); // Request a Writer from the the Publisher. OwnershipDataDataWriter = createDataWriter(OwnershipDataPublisher, g_StockTopic, FALSE, ownership_strength); // Publish a Stock Sample reflecting the state of the Msg DataWriter. OwnershipDataSample = OwnershipData_Stock__alloc(); OwnershipDataSample->ticker = DDS_string_alloc(stringLength); snprintf(OwnershipDataSample->ticker, stringLength + 1, "%s", ticker); OwnershipDataSample->price = 0.0; OwnershipDataSample->publisher = DDS_string_dup(publisher_name); OwnershipDataSample->strength = ownership_strength; userHandle = OwnershipData_StockDataWriter_register_instance(OwnershipDataDataWriter, OwnershipDataSample); //Publisher publishes the prices in dollars printf("\n=== [Publisher] Publisher %d with strength : ", ownership_strength); printf("\n / sending %d prices...", nb_iteration); // The subscriber should display the prices sent by the publisher with the highest ownership strength price = 10.0f; for( sampleIndex = 0; sampleIndex < nb_iteration ; ++sampleIndex ) { OwnershipDataSample->price = price; writeStockSample(OwnershipDataDataWriter, userHandle, OwnershipDataSample); os_nanoSleep(os_delay200); price = price + 0.5f; } if( isStoppingSubscriber == TRUE ) { // This special price gives the end signal to the Subscriber: OwnershipDataSample->price = (DDS_float) -1.0f; writeStockSample(OwnershipDataDataWriter, userHandle, OwnershipDataSample); } // This to make sure the Subscriber will get all the Samples. os_nanoSleep(os_delay2000); OwnershipData_StockDataWriter_unregister_instance (OwnershipDataDataWriter, OwnershipDataSample, userHandle); // Cleanup DDS from the created Entities. deleteDataWriter(OwnershipDataPublisher, OwnershipDataDataWriter); deletePublisher(OwnershipDataPublisher); deleteTopic(g_StockTopic); deleteParticipant(); // Cleanup C allocations, // recursively freeing the allocated structures and sequences using the OpenSplice API. DDS_free(OwnershipDataSample); // Print out an empty line, just to let behind a clean new line for the shell.. printf("\n\r"); return 0; }
int main(int argc, char *argv[]) { char* partition_name = "ContentFilteredTopic example"; DDS_Subscriber contentFilteredTopicDataSubscriber; DDS_DataReader contentFilteredTopicDataDataReader; ContentFilteredTopicData_Stock* contentFilteredTopicDataSample; DDS_InstanceHandle_t userHandle; DDS_sequence_ContentFilteredTopicData_Stock* msgList = DDS_sequence_ContentFilteredTopicData_Stock__alloc(); DDS_SampleInfoSeq* infoSeq = DDS_SampleInfoSeq__alloc(); c_bool isClosed = FALSE; unsigned long j, userInput, timeOut; const char *filterValueToSubscribe; DDS_char* contentFilteredStockTopicName = "MyStockTopic"; DDS_ContentFilteredTopic contentFilteredTopic; int filter_expressionLength; const char* filter_expressionPrefix = "ticker = '"; const char* filter_expressionSuffix = "'"; DDS_char *filter_expression; const DDS_StringSeq* filter_parameters = DDS_StringSeq__alloc(); os_time delay_200ms = { 0, 200000000 }; int count = 0; // usage : ContentFilteredTopicDataSubscriber <topic's content filtering string> if( argc < 2 ) { usage(); } printf("=== ContentFilteredTopicDataSubscriber"); // Removed to comply with expected results //printf("\n\n Parameter is \"%s\"", argv[1]); filterValueToSubscribe = argv[1]; createParticipant( partition_name ); // Register Stock Topic's type in the DDS Domain. g_StockTypeSupport = (DDS_TypeSupport) ContentFilteredTopicData_StockTypeSupport__alloc(); checkHandle(g_StockTypeSupport, "ContentFilteredTopicData_StockTypeSupport__alloc"); registerStockType(g_StockTypeSupport); // Create Stock Topic in the DDS Domain. g_StockTypeName = (char*) ContentFilteredTopicData_StockTypeSupport_get_type_name(g_StockTypeSupport); g_StockTopic = createTopic("StockTrackerExclusive", g_StockTypeName); DDS_free(g_StockTypeName); DDS_free(g_StockTypeSupport); // Create the Subscriber's in the DDS Domain. contentFilteredTopicDataSubscriber = createSubscriber(); // create subscription filter filter_expressionLength = strlen(filter_expressionPrefix); filter_expressionLength += strlen(filterValueToSubscribe); filter_expressionLength += strlen(filter_expressionSuffix); filter_expression = DDS_string_alloc(filter_expressionLength); snprintf(filter_expression, filter_expressionLength + 1, "%s%s%s", filter_expressionPrefix, filterValueToSubscribe, filter_expressionSuffix); // create ContentFilteredTopic to retrieve only the samples with the given Stock. contentFilteredTopic = createContentFilteredTopic(contentFilteredStockTopicName, g_StockTopic, filter_expression, filter_parameters); // create Filtered DataReader printf( "\n=== [ContentFilteredTopicDataSubscriber] Subscription filter : %s", filter_expression ); // Request a Reader from the the Subscriber. contentFilteredTopicDataDataReader = createContentFilteredDataReader(contentFilteredTopicDataSubscriber, contentFilteredTopic); printf( "\n=== [ContentFilteredTopicDataSubscriber] Ready ..." ); do { g_status = ContentFilteredTopicData_StockDataReader_take(contentFilteredTopicDataDataReader, msgList, infoSeq, DDS_LENGTH_UNLIMITED, DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE); checkStatus(g_status, "ContentFilteredTopicData_StockDataReaderView_take"); if( msgList->_length > 0 ) { j = 0; do { contentFilteredTopicDataSample = &msgList->_buffer[j]; if( infoSeq->_buffer[j].valid_data ) { if( contentFilteredTopicDataSample->price != (DDS_float) -1.0f ) { int floatWidth = ( ((DDS_float) contentFilteredTopicDataSample->price) - ((long) contentFilteredTopicDataSample->price) ) ? 1 : 0; printf("\n=== [ContentFilteredTopicDataSubscriber] receives stockQuote : (%s, %.*f)", contentFilteredTopicDataSample->ticker, floatWidth, contentFilteredTopicDataSample->price); } else { isClosed = TRUE; } } } while( ++j < msgList->_length ); g_status = ContentFilteredTopicData_StockDataReader_return_loan(contentFilteredTopicDataDataReader, msgList, infoSeq); checkStatus(g_status, "ContentFilteredTopicData_StockDataReader_return_loan"); if(isClosed == FALSE) { os_nanoSleep(delay_200ms); ++count; } } } while( isClosed == FALSE && count < 1500); // We dont want the example to run indefinitely printf("\n=== [ContentFilteredTopicDataSubscriber] Market Closed\n"); // Cleanup DDS from the created Entities. deleteDataReader(contentFilteredTopicDataSubscriber, contentFilteredTopicDataDataReader); deleteSubscriber(contentFilteredTopicDataSubscriber); deleteContentFilteredTopic(contentFilteredTopic); deleteTopic(g_StockTopic); deleteParticipant(); // Cleanup C allocations, // recursively freeing the allocated structures and sequences using the OpenSplice API. DDS__free(msgList); DDS__free(infoSeq); // Print out an empty line, just to let behind a clean new line for the shell.. // Removed to comply with expected results //printf("\n\r"); return 0; }
int main(int argc, char *argv[]) { DDS_Subscriber OwnershipDataSubscriber; DDS_DataReader OwnershipDataDataReader; OwnershipData_Stock* OwnershipDataSample; DDS_InstanceHandle_t userHandle; DDS_sequence_OwnershipData_Stock* msgList = DDS_sequence_OwnershipData_Stock__alloc(); DDS_SampleInfoSeq* infoSeq = DDS_SampleInfoSeq__alloc(); c_bool isClosed; int count = 0; unsigned long j, userInput, timeOut; os_time os_delay200 = { 0, 200000000 }; printf("\n\n Starting LifecycleSubscriber..."); createParticipant("Ownership example"); // Register Stock Topic's type in the DDS Domain. g_StockTypeSupport = (DDS_TypeSupport) OwnershipData_StockTypeSupport__alloc(); checkHandle(g_StockTypeSupport, "OwnershipData_StockTypeSupport__alloc"); registerStockType(g_StockTypeSupport); // Create Stock Topic in the DDS Domain. g_StockTypeName = (char*) OwnershipData_StockTypeSupport_get_type_name(g_StockTypeSupport); g_StockTopic = createTopic("StockTrackerExclusive", g_StockTypeName); DDS_free(g_StockTypeName); DDS_free(g_StockTypeSupport); // Create the Subscriber's in the DDS Domain. OwnershipDataSubscriber = createSubscriber(); // Request a Reader from the the Subscriber. OwnershipDataDataReader = createDataReader(OwnershipDataSubscriber, g_StockTopic); printf("\n\n ===[OwnershipDataSubscriber] Ready..."); printf("\n\n Ticker Price Publisher ownership strength"); isClosed = FALSE; do { g_status = OwnershipData_StockDataReader_take(OwnershipDataDataReader, msgList, infoSeq, 1, DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE); checkStatus(g_status, "OwnershipData_StockDataReaderView_take"); if( msgList->_length > 0 ) { j = 0; do { OwnershipDataSample = &msgList->_buffer[j]; // When is this supposed to happen? // Needs comment... if( infoSeq->_buffer[j].valid_data ) { printf("\n %s %8.1f %s %d", OwnershipDataSample->ticker, OwnershipDataSample->price, OwnershipDataSample->publisher, OwnershipDataSample->strength); if( OwnershipDataSample->price == (DDS_float) -1.0f ) { printf("\n ===[OwnershipDataSubscriber] OwnershipDataSample->price == -1.0f "); isClosed = TRUE; } } } while( ++j < msgList->_length ); g_status = OwnershipData_StockDataReader_return_loan(OwnershipDataDataReader, msgList, infoSeq); checkStatus(g_status, "OwnershipData_StockDataReaderView_return_loan"); } os_nanoSleep(os_delay200); ++count; } while( isClosed == FALSE && count < 1500 ); printf("\n\n ===[OwnershipDataSubscriber] Market closed"); // Cleanup DDS from the created Entities. deleteDataReader(OwnershipDataSubscriber, OwnershipDataDataReader); deleteSubscriber(OwnershipDataSubscriber); deleteTopic(g_StockTopic); deleteParticipant(); // Cleanup C allocations, // recursively freeing the allocated structures and sequences using the OpenSplice API. DDS__free(msgList); DDS__free(infoSeq); // Print out an empty line, just to let behind a clean new line for the shell.. printf("\n\r"); return 0; }