diff --git a/srcC/cyclone-dds-cmake/CMakeLists.txt b/srcC/cyclone-dds-cmake/CMakeLists.txt index f2ddf0f..13c42c0 100644 --- a/srcC/cyclone-dds-cmake/CMakeLists.txt +++ b/srcC/cyclone-dds-cmake/CMakeLists.txt @@ -1,13 +1,33 @@ cmake_minimum_required(VERSION 3.16) project(shape LANGUAGES C) +option(BUILD_SHARED_LIBS "Build using shared libraries by default" ON) + # Find the CycloneDDS package. +if(NOT BUILD_SHARED_LIBS) + find_package(OpenSSL REQUIRED) +endif() find_package(CycloneDDS REQUIRED) set(EXECUTABLE_NAME "eclipse_cyclone-${CycloneDDS_VERSION}_shape_main_linux") -idlc_generate(TARGET shape_lib FILES "../shape.idl" WARNINGS no-implicit-extensibility) + +if(BUILD_SHARED_LIBS) + idlc_generate(TARGET shape_lib FILES "../shape.idl" WARNINGS no-implicit-extensibility) +else() + if(NOT EXISTS ${IDLC_ROOT}/idlc) + message(FATAL_ERROR "The root directory of the idlc executable must be specified using IDLC_ROOT for static builds") + endif() + execute_process(COMMAND ${IDLC_ROOT}/idlc shape.idl + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/.. + RESULT_VARIABLE idlc_rez + OUTPUT_VARIABLE idlc_var) +endif() add_executable(${EXECUTABLE_NAME} ../shape_main.c) +if(NOT BUILD_SHARED_LIBS) + add_library(shape_lib shape.c shape.h) + target_link_libraries(shape_lib CycloneDDS::ddsc m) +endif() target_compile_definitions(${EXECUTABLE_NAME} PUBLIC -DCYCLONE_DDS) -target_link_libraries(${EXECUTABLE_NAME} shape_lib CycloneDDS::ddsc m) \ No newline at end of file +target_link_libraries(${EXECUTABLE_NAME} shape_lib CycloneDDS::ddsc m) diff --git a/srcC/shape_main.c b/srcC/shape_main.c index 077c7fe..2e11b79 100644 --- a/srcC/shape_main.c +++ b/srcC/shape_main.c @@ -431,15 +431,15 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options {"read-period", required_argument, NULL, 'A'}, {"final-instance-state", required_argument, NULL, 'M'}, {"access-scope", required_argument, NULL, 'C'}, - {"coherent", required_argument, NULL, 'T'}, - {"ordered", required_argument, NULL, 'O'}, + {"coherent", no_argument, NULL, 'T'}, + {"ordered", no_argument, NULL, 'O'}, {"coherent-sample-count", required_argument, NULL, 'H'}, {"additional-payload-size", required_argument, NULL, 'B'}, {"num-topics", required_argument, NULL, 'E'}, {"lifespan", required_argument, NULL, 'l'}, {"num-instances", required_argument, NULL, 'I'}, {"num-iterations", required_argument, NULL, 'n'}, - {"take-read", required_argument, NULL, 'K'}, + {"take-read", no_argument, NULL, 'K'}, {"time-filter", required_argument, NULL, 'i'}, {"periodic-announcement", required_argument, NULL, 'N'}, {"datafrag-size", required_argument, NULL, 'Z'}, @@ -518,7 +518,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options break; case 'i': { int64_t time_input = 0; - int converted_param = sscanf(optarg, "%lld", &time_input); + int converted_param = sscanf(optarg, "%" PRId64 , &time_input); if (converted_param == 0) { log_message(logger, ERROR, "unrecognized value for timebasedfilter_interval %s", &optarg[0]); parse_ok = false; @@ -531,7 +531,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options } case 'f': { int64_t time_input = 0; - int converted_param = sscanf(optarg, "%lld", &time_input); + int converted_param = sscanf(optarg, "%" PRId64 , &time_input); if (converted_param == 0) { log_message(logger, ERROR, "unrecognized value for deadline_interval %s", &optarg[0]); parse_ok = false; @@ -614,7 +614,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options } case 'W': { dds_duration_t converted_param = 0; - if (sscanf(optarg, "%lld", &converted_param) == 0) { + if (sscanf(optarg, "%" PRId64 , &converted_param) == 0) { log_message(logger, ERROR, "unrecognized value for write-period %s", &optarg[0]); parse_ok = false; } else if (converted_param < 0) { @@ -626,7 +626,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options } case 'A': { dds_duration_t converted_param = 0; - if (sscanf(optarg, "%lld", &converted_param) == 0) { + if (sscanf(optarg, "%" PRId64 , &converted_param) == 0) { log_message(logger, ERROR, "unrecognized value for read-period %s", &optarg[0]); parse_ok = false; } else if (converted_param < 0) { @@ -648,7 +648,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options } case 'l': { dds_duration_t converted_param = 0; - if (sscanf(optarg, "%lld", &converted_param) == 0) { + if (sscanf(optarg, "%" PRId64, &converted_param) == 0) { log_message(logger, ERROR, "unrecognized value for lifespan %s", &optarg[0]); parse_ok = false; } else if (converted_param < 0) { @@ -667,6 +667,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options break; case 'd': shape_options->dispose = true; + break; default: log_message(logger, ERROR, "unrecognized value for final-instance-state %s", &optarg[0]); parse_ok = false; @@ -754,7 +755,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options } case 'N': { dds_duration_t converted_param = 0; - if (sscanf(optarg, "%lld", &converted_param) == 0){ + if (sscanf(optarg, "%" PRId64 , &converted_param) == 0){ log_message(logger, ERROR, "unrecognized value for periodic-announcement %s", &optarg[0]); parse_ok = false; } else if (converted_param < 0) { @@ -816,15 +817,15 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options printf(" DataRepresentation = %d\n", shape_options->data_representation); printf(" HistoryDepth = %d\n", shape_options->history_depth); printf(" OwnershipStrength = %d\n",shape_options->ownership_strength); - printf(" TimeBasedFilterInterval = %u ms\n",shape_options->timebasedfilter_interval_us / 1000ll); - printf(" DeadlineInterval = %u ms\n", shape_options->deadline_interval_us / 1000ll); + printf(" TimeBasedFilterInterval = %" PRId64 " ms\n",shape_options->timebasedfilter_interval_us / INT64_C(1000)); + printf(" DeadlineInterval = %" PRId64 " ms\n", shape_options->deadline_interval_us / INT64_C(1000)); printf(" Shapesize = %d\n", shape_options->shapesize); printf(" Reading method = %s\n", (shape_options->use_read ? (shape_options->take_read_next_instance ? "read_next_instance" : "read") : (shape_options->take_read_next_instance ? "take_next_instance" : "take"))); - printf(" Write period = %u ms\n", shape_options->write_period_us / 1000ll); - printf(" Read period = %u ms\n", shape_options->read_period_us / 1000ll); - printf(" Lifespan = %u ms\n", shape_options->lifespan_us / 1000ll); + printf(" Write period = %" PRId64 " ms\n", shape_options->write_period_us / INT64_C(1000)); + printf(" Read period = %" PRId64 " ms\n", shape_options->read_period_us / INT64_C(1000)); + printf(" Lifespan = %" PRId64 " ms\n", shape_options->lifespan_us / INT64_C(1000)); printf(" Number of iterations = %u\n", shape_options->num_iterations); printf(" Number of instances = %u\n", shape_options->num_instances); printf(" Number of entities = %u\n", shape_options->num_topics); @@ -835,7 +836,7 @@ bool parse(int argc, char *argv[], Logger* logger, ShapeOptions_t* shape_options printf(" Additional Payload Size = %u\n", shape_options->additional_payload_size); printf(" Final Instance State = %s\n", (shape_options->unregister ? "Unregister" : (shape_options->dispose ? "Dispose" : "not specified"))); - printf(" Periodic Announcement Period = %u ms\n", shape_options->periodic_announcement_period_us / 1000ll); + printf(" Periodic Announcement Period = %" PRId64 " ms\n", shape_options->periodic_announcement_period_us / INT64_C(1000)); printf(" Data Fragmentation Size = %u bytes\n", shape_options->datafrag_size); if (shape_options->topic_name != NULL){ printf(" Topic = %s\n", shape_options->topic_name); @@ -1331,7 +1332,7 @@ bool init_subscriber(const ShapeOptions_t* opts, ShapeApp_t* app) { set_deadline_interval(dr_qos, opts->deadline_interval_us * 1000ll, app->logger); set_history_depth(dr_qos, opts->history_depth, app->logger); - if (opts->cft_expression != NULL) { + if (opts->cft_expression != NULL || opts->color != NULL) { log_message(app->logger, ERROR, "ContentFilterTopic Not Supported"); return false; } @@ -1485,7 +1486,7 @@ bool shape_init (ShapeApp_t* app, const ShapeOptions_t* opts, Logger* logger) { } log_message(logger, DEBUG, "Topics created:"); for (unsigned int i = 0; i < opts->num_topics; ++i) { - log_message(logger, DEBUG, " topic(%d)=%p", i, (void*)app->topics[i]); + log_message(logger, DEBUG, " topic(%d)=%u", i, app->topics[i]); } if (opts->publish) { @@ -1517,7 +1518,7 @@ bool run_subscriber(ShapeApp_t app, ShapeOptions_t opts) { dds_sample_info_t sample_infos[MAX_SAMPLES]; void* samples[MAX_SAMPLES]; - for( size_t i = 0; i < MAX_SAMPLES; i ++) samples[i] = ShapeType__alloc(); + for( size_t i = 0; i < MAX_SAMPLES; i ++) samples[i] = NULL; if(opts.coherent_set_enabled) { printf("Reading coherent sets, iteration %u\n", n); } @@ -1584,8 +1585,8 @@ bool run_subscriber(ShapeApp_t app, ShapeOptions_t opts) { printf("\n"); } if (sample_info->instance_state != DDS_IST_ALIVE) { - ShapeType shape_key; - dds_instance_get_key(app.readers[i], sample_info->instance_handle, &shape_key); + ShapeType shape_key = *sample; + //dds_instance_get_key(app.readers[i], sample_info->instance_handle, &shape_key); if (sample_info->instance_state == DDS_IST_NOT_ALIVE_NO_WRITERS) { dds_entity_t reader_topic = dds_get_topic(app.readers[i]); char temp; @@ -1606,6 +1607,7 @@ bool run_subscriber(ShapeApp_t app, ShapeOptions_t opts) { } } dds_return_loan(app.readers[i], (void**)samples, MAX_SAMPLES); + samples[0] = NULL; previous_handles[i] = sample_infos[0].instance_handle; } log_message(app.logger, DEBUG, "retval: %d", retval); @@ -1622,7 +1624,6 @@ bool run_subscriber(ShapeApp_t app, ShapeOptions_t opts) { all_done = 1; } - for( size_t i = 0; i < MAX_SAMPLES; i ++) ShapeType_free(samples[i],DDS_FREE_ALL); usleep(opts.read_period_us); } @@ -1710,9 +1711,9 @@ bool run_publisher(ShapeApp_t app, ShapeOptions_t opts) { //Publish different instances with the same content (except for the color) if (opts.num_instances > 1) { if (strlen(opts.color) > 0 && j > 0) { - sscanf(shape.color, "%s%u", opts.color, j); + sprintf(shape.color, "%s%u", opts.color, j); } else { - sscanf(shape.color, "%s", opts.color); + sprintf(shape.color, "%s", opts.color); } } dds_return_t rc = dds_write(app.writers[i], &shape);