diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/README.md b/README.md index 9df96bb..839a565 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,41 @@ # UMExamples UMExamples provides sample applications for users of Ultra Messaging -Head over to http://ultramessaging.github.io/UMExamples/ to view the Examples +Go to https://ultramessaging.github.io/UMExamples/ so see them rendered +and user-friendly. + + +## Semlit + +The examples use a documentation toolset called "semlit". +Go to https://github.com/fordsfords/semlit to get it. +Place ``semlit.sh`` and ``semlit.pl`` into your PATH. + + +## Creating Examples + +Here is how I created the "ss_frag" example: + +```mkdir ss_frag +cd ss_frag +mkdir c +cp ../cancelling_timers/README.txt . +vi README.txt``` + +Change appropriately. + +```cp ../cancelling_timers/intro.sldoc . +vi intro.sldoc``` + +Change appropriately. + +```cp ../cancelling_timers/c/cancelling_timers.sldoc c/ss_frag.sldoc +cp ../cancelling_timers/c/cancelling_timers_c.slsrc c/ss_frag_c.slsrc +cd c +vi ss_frag.sldoc``` + +In a separate window: + +```cd c +vi ss_frag_c.slsrc``` + diff --git a/bld.sh b/bld.sh index 5034da8..665fb76 100755 --- a/bld.sh +++ b/bld.sh @@ -7,10 +7,18 @@ else : exit 1 fi -# Find all the examples -find * -name README.txt -print >bld.tmp +if [ -n "$1" ]; then : + if [ ! -d "$1" ]; then : + echo "$1 not found" >&2 + exit 1 + fi + find "$1" -name README.txt -print >bld.tmp +else : + # Find all the examples + find * -name README.txt -print >bld.tmp +fi -# Build all the semiliterate docs +# Build the semiliterate docs cat bld.tmp | while read F; do : # find each tool T=`dirname $F` cd $T @@ -22,12 +30,19 @@ cat bld.tmp | while read F; do : # find each tool semlit.sh "$T.sldoc" # Don't let example maintainers edit the output files chmod -w *.c *.h *.java *.cs >/dev/null 2>&1 + # Try compile (check for errors) + if ls *.c >/dev/null 2>&1; then : + echo "bld.sh: Info: gcc -I$LBM_PLATFORM/include -g -c *.c" + gcc $* -I$LBM_PLATFORM/include -g -c *.c + rm -f *.o + fi cd .. done cd .. done echo "bld.sh: Info: building html index files" +find * -name README.txt -print >bld.tmp perl bld.pl bld.tmp rm bld.tmp diff --git a/c_index.html b/c_index.html index 39556cf..45b66c0 100644 --- a/c_index.html +++ b/c_index.html @@ -1,9 +1,17 @@ - -
-
Examples written in C.
@@ -18,6 +26,7 @@| mtools | C | Informatica "mtools" are a set of multicast test tools. Binaries and source code available for free. |
| cancelling_timers | C Java C#/.NET | Example on how a context can schedule and safely cancel timer callbacks |
| check_flight_size_ewouldblock | C Java C#/.NET | A send can fail with an EWOULDBLOCK error, which can have different root causes. One cause for a persisted source is exceeding flight size. This example shows how to determine if flight size is the cause of an EWOULDBLOCK error. |
| clean_shutdown | C Java C#/.NET | Example on how to properly clean up a UM application |
| sequential_mode | C Java C#/.NET | Example on how to run a LBM application in sequential mode with a separate context thread |
| setting_attributes | C Java C#/.NET | Examples on setting UM attributes via the API |
| source_notify_callbacks | C Java C#/.NET | A sample application that demonstrates how to configure and code the source_notification_callback feature for receivers |
| src_rsp | C | A sample application that demonstrates source-based request responses. |
| ss_frag | C | A sample application that demonstrates application-level message fragmentation/reassembly for Smart Source. |
| ump_receiver_callbacks | C Java C#/.NET | A sample application that handles all UMP receiver callbacks and logs important data |
| ump_src_failover | C | Example UMP source application that demonstrates how a persisted source can failover to a backup store |
This software and documentation are provided only under a separate license +agreement containing restrictions on use and disclosure. +No part of this document may be reproduced or transmitted in any form, +by any means (electronic, photocopying, recording or otherwise) +without prior consent of Informatica LLC. + +
A current list of Informatica trademarks is available on the web at +https://www.informatica.com/trademarks.html. + +
Portions of this software and/or documentation are subject to copyright +held by third parties. +Required third party notices are included with the product. + +
Informatica software is protected by patents as detailed at +https://www.informatica.com/legal/patents.html. + +
The information in this documentation is subject to change without notice. +If you find any problems in this documentation, please report them to us in +writing at Informatica LLC 2100 Seaport Blvd. Redwood City, CA 94063. + +
Informatica products are warranted according to the terms and conditions
+of the agreements under which they are provided.
+
INFORMATICA LLC PROVIDES THE INFORMATION IN THIS DOCUMENT "AS IS" WITHOUT
+WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT ANY WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OR
+CONDITION OF NON-INFRINGEMENT.
+
-00027 typedef enum {PENDING, FIRED, CANCELED} state_type_e;
-00028 typedef struct app_timer_s {
-00029 int id;
-00030 state_type_e state;
-00031 int sync;
-00032 } app_timer_s;
+00046 typedef enum {PENDING, FIRED, CANCELED} state_type_e;
+00047 typedef struct app_timer_s {
+00048 int id;
+00049 state_type_e state;
+00050 int sync;
+00051 } app_timer_s;
@@ -46,11 +46,8 @@ -00072 err = lbm_context_attr_create(&cattr); -00073 EX_LBM_CHK(err); -00074 -00075 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00076 EX_LBM_CHK(err); +00091 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00092 EX_LBM_CHK(err);@@ -59,18 +56,19 @@
-00037 int sample_timer_handler(lbm_context_t *ctx, const void *clientd)
-00038 {
-00039 struct app_timer_s *my_timer = (struct app_timer_s *)clientd;
-00040 if (my_timer->state != PENDING) {
-00041 fprintf(stderr, "ERROR: Timer executed and should have been cancelled\n");
-00042 exit(1);
-00043 }
-00044
-00045 fprintf(stderr, "ERROR: This timer should have been cancelled by now\n");
-00046
-00047 return 0;
-00048 }
+00054 /* Timer callback function */
+00055 int sample_timer_handler(lbm_context_t *ctx, const void *clientd)
+00056 {
+00057 struct app_timer_s *my_timer = (struct app_timer_s *)clientd;
+00058 if (my_timer->state != PENDING) {
+00059 fprintf(stderr, "ERROR: Timer executed and should have been cancelled\n");
+00060 exit(1);
+00061 }
+00062
+00063 fprintf(stderr, "ERROR: This timer should have been cancelled by now\n");
+00064
+00065 return 0;
+00066 } /* sample_timer_handler */
@@ -82,17 +80,17 @@
-00050 int cancel_timer_cb(lbm_context_t *ctx, const void *clientd)
-00051 {
-00052 struct app_timer_s *my_timer = (struct app_timer_s *)clientd;
-00053 if (my_timer->state == PENDING) {
-00054 lbm_cancel_timer(ctx, my_timer->id, NULL);
-00055 my_timer->state = CANCELED;
-00056 }
-00057 my_timer->sync = 0;
-00058
-00059 return 0;
-00060 }
+00069 int cancel_timer_cb(lbm_context_t *ctx, const void *clientd)
+00070 {
+00071 struct app_timer_s *my_timer = (struct app_timer_s *)clientd;
+00072 if (my_timer->state == PENDING) {
+00073 lbm_cancel_timer(ctx, my_timer->id, NULL);
+00074 my_timer->state = CANCELED;
+00075 }
+00076 my_timer->sync = 0;
+00077
+00078 return 0;
+00079 } /* cancel_timer_cb */
@@ -102,11 +100,11 @@
-00078 my_timer.state = PENDING;
-00079 if ((my_timer.id = lbm_schedule_timer(ctx, sample_timer_handler, &my_timer, NULL, 10000)) == -1) {
-00080 fprintf(stderr, "%s:%d, lbm error: '%s'\n", __FILE__, __LINE__, lbm_errmsg());
-00081 exit(1);
-00082 }
+00094 my_timer.state = PENDING;
+00095 if ((my_timer.id = lbm_schedule_timer(ctx, sample_timer_handler, &my_timer, NULL, 10000)) == -1) {
+00096 fprintf(stderr, "%s:%d, lbm error: '%s'\n", __FILE__, __LINE__, lbm_errmsg());
+00097 exit(1);
+00098 }
@@ -115,11 +113,11 @@
-00087 if (my_timer.state == PENDING) {
-00088 lbm_schedule_timer(ctx, cancel_timer_cb, &my_timer, NULL, 0);
-00089 /* timer might still fire at this point. */
-00090 my_timer.sync = 1;
-00091 }
+00103 if (my_timer.state == PENDING) {
+00104 lbm_schedule_timer(ctx, cancel_timer_cb, &my_timer, NULL, 0);
+00105 /* timer might still fire at this point. */
+00106 my_timer.sync = 1;
+00107 }
@@ -128,8 +126,8 @@ -00093 while (my_timer.sync) -00094 SLEEP(1); +00109 while (my_timer.sync) +00110 SLEEP(1);@@ -139,14 +137,14 @@
-00018 /* Example error checking macro. Include after each UM call. */
-00019 #define EX_LBM_CHK(err) do { \
-00020 if ((err) < 0) { \
-00021 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \
-00022 __FILE__, __LINE__, lbm_errmsg()); \
-00023 exit(1); \
-00024 } \
-00025 } while (0)
+00037 /* Example error checking macro. Include after each UM call. */
+00038 #define EX_LBM_CHK(err) do { \
+00039 if ((err) < 0) { \
+00040 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \
+00041 __FILE__, __LINE__, lbm_errmsg()); \
+00042 exit(1); \
+00043 } \
+00044 } while (0)
@@ -162,20 +160,20 @@ Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>diff --git a/cancelling_timers/c/cancelling_timers_c.slsrc b/cancelling_timers/c/cancelling_timers_c.slsrc index 72a30dd..e2919c2 100644 --- a/cancelling_timers/c/cancelling_timers_c.slsrc +++ b/cancelling_timers/c/cancelling_timers_c.slsrc @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* cancelling_timers.c - see http://ultramessaging.github.io/UMExamples/cancelling_timers/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include
diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.c b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.c index 984f4bf..c051aaf 100644 --- a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.c +++ b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.c @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* check_flight_size_ewouldblock.c - see http://ultramessaging.github.io/UMExamples/check_flight_size_ewouldblock/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 -00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 00067 00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 00083 00084 00085 00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 00099 00100 00101 00102 -00103 -00104 -00105 - /* Code Disclaimer? */ +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 + /* cancelling_timers.c - see http://ultramessaging.github.io/UMExamples/cancelling_timers/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -149,15 +185,14 @@ typedef enum {PENDING, FIRED, CANCELED} state_type_e; typedef struct app_timer_s { - int id; - state_type_e state; - int sync; + int id; + state_type_e state; + int sync; } app_timer_s; - int wait = 1; - /* Timer callback function */ - int sample_timer_handler(lbm_context_t *ctx, const void *clientd) + /* Timer callback function */ + int sample_timer_handler(lbm_context_t *ctx, const void *clientd) { struct app_timer_s *my_timer = (struct app_timer_s *)clientd; if (my_timer->state != PENDING) { @@ -168,7 +203,8 @@ fprintf(stderr, "ERROR: This timer should have been cancelled by now\n"); return 0; - } + } /* sample_timer_handler */ + int cancel_timer_cb(lbm_context_t *ctx, const void *clientd) { @@ -180,22 +216,19 @@ my_timer->sync = 0; return 0; - } + } /* cancel_timer_cb */ + - main() + int main(int argc, char **argv) { lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ app_timer_s my_timer; + int err; my_timer.sync = 0; /* Initialize context atrributes and create context */ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); my_timer.state = PENDING; @@ -219,13 +252,14 @@ /* Clean up */ err = lbm_context_delete(ctx); EX_LBM_CHK(err); - + #if defined(_MSC_VER) /* Windows-specific cleanup overhead */ WSACleanup(); #endif - } + return 0; + } /* main */ @@ -15,18 +34,27 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + #define DEFAULT_APP_FLIGHT_SIZE 500 /* Used for checking flight size */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_topic_t *topic; /* Topic object */ - lbm_src_t *src; /* Source object */ - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int inflight; /* Object used for checking inflight counters */ + lbm_context_t *ctx; /* Context object */ + lbm_topic_t *topic; /* Topic object */ + lbm_src_t *src; /* Source object */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + int inflight; /* Object used for checking inflight counters */ char flight[4]; - int err; /* Used for checking API return codes */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -39,71 +67,44 @@ main() } #endif - if (lbm_context_attr_create(&cattr) != 0) - { - fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - - if (lbm_src_topic_attr_create(&tattr) != 0) - { - fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); sprintf(flight, "%d", DEFAULT_APP_FLIGHT_SIZE); - if (lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight) != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight); + EX_LBM_CHK(err); /* Assuming there is a store running on the localhost at port 29999 */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); + EX_LBM_CHK(err); err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); - if (err) - { - printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - if (err) - { - printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); while(1) { - if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); + if (err == LBM_FAILURE) { if (lbm_errnum() == LBM_EWOULDBLOCK) - { - if (lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL) == 0) + { + err = lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL); + EX_LBM_CHK(err); + + /* Is inflight counter is equal to the configured flight size? */ + if (inflight == DEFAULT_APP_FLIGHT_SIZE) { - /* Check to see if the inflight counter is equal to the configured flight size */ - if (inflight == DEFAULT_APP_FLIGHT_SIZE) - { - /* Print alert */ - printf("ALERT: Source is blocked on flight size: %d\n", inflight); - } + printf("ALERT: Source is blocked on flight size: %d\n", inflight); } } } } -} - + return 0; +} /* main */ diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc index f2e06b6..e2b6785 100644 --- a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc +++ b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc @@ -7,8 +7,8 @@ =semlit,include,../intro.sldoc= There is one program source file, and a store configuration XML:
-
- =semlit,srcfile,check_flight_size_ewouldblock.slsrc,check_flight_size_ewouldblock.c=
-- =semlit,srcfile,check_flight_size_ewouldblock_store.slsrc,store.xml=
+- =semlit,srcfile,check_flight_size_ewouldblock_c.slsrc,check_flight_size_ewouldblock.c=
+- =semlit,srcfile,check_flight_size_ewouldblock_store_xml.slsrc,store.xml=
Program explanation: check_flight_size_ewouldblock.c
Define a Flight Size
diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc.html b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc.html index 804909f..18e4ee1 100644 --- a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc.html +++ b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.sldoc.html @@ -56,7 +56,7 @@Define a Flight Size
size in Ultra Messaging is 1000 messages. For the purpose of this example, it is defined to 500.-00018 #define DEFAULT_APP_FLIGHT_SIZE 500 /* Used for checking flight size */ +00046 #define DEFAULT_APP_FLIGHT_SIZE 500 /* Used for checking flight size */@@ -65,14 +65,13 @@Declare Variables
and the char flight[4] variable which is being used to set the flight size via the API.-00022 lbm_context_t *ctx; /* Context object */ -00023 lbm_topic_t *topic; /* Topic object */ -00024 lbm_src_t *src; /* Source object */ -00025 lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ -00026 lbm_context_attr_t * cattr; /* Context attribute object */ -00027 int inflight; /* Object used for checking inflight counters */ -00028 char flight[4]; -00029 int err; /* Used for checking API return codes */ +00051 lbm_context_t *ctx; /* Context object */ +00052 lbm_topic_t *topic; /* Topic object */ +00053 lbm_src_t *src; /* Source object */ +00054 lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ +00055 int inflight; /* Object used for checking inflight counters */ +00056 char flight[4]; +00057 int err;@@ -81,18 +80,8 @@Create the context
Creating a Context-00042 if (lbm_context_attr_create(&cattr) != 0) -00043 { -00044 fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); -00045 exit(1); -00046 } -00047 -00048 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00049 if (err) -00050 { -00051 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00052 exit(1); -00053 } +00070 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00071 EX_LBM_CHK(err);@@ -129,39 +118,22 @@Create Source
-00055 if (lbm_src_topic_attr_create(&tattr) != 0) -00056 { -00057 fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); -00058 exit(1); -00059 } -00060 -00061 sprintf(flight, "%d", DEFAULT_APP_FLIGHT_SIZE); -00062 if (lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight) != 0 ) -00063 { -00064 fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); -00065 exit(1); -00066 } -00067 -00068 /* Assuming there is a store running on the localhost at port 29999 */ -00069 if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) -00070 { -00071 fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); -00072 exit(1); -00073 } -00074 -00075 err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); -00076 if (err) -00077 { -00078 printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); -00079 exit(1); -00080 } -00081 -00082 err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); -00083 if (err) -00084 { -00085 printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); -00086 exit(1); -00087 } +00073 err = lbm_src_topic_attr_create(&tattr); +00074 EX_LBM_CHK(err); +00075 +00076 sprintf(flight, "%d", DEFAULT_APP_FLIGHT_SIZE); +00077 err = lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight); +00078 EX_LBM_CHK(err); +00079 +00080 /* Assuming there is a store running on the localhost at port 29999 */ +00081 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); +00082 EX_LBM_CHK(err); +00083 +00084 err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); +00085 EX_LBM_CHK(err); +00086 +00087 err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); +00088 EX_LBM_CHK(err);@@ -170,7 +142,7 @@Main Send Loop
to stdout whenever the source fails to send a message due to flight size.-00089 while(1) +00090 while(1)@@ -182,7 +154,8 @@Send a Message
by the UM library.-00091 if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) +00092 err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); +00093 if (err == LBM_FAILURE)@@ -192,7 +165,7 @@Check Send Error
that either lbm_src_send() failed because it hit flight size, or because it hit the rate limiter.-00093 if (lbm_errnum() == LBM_EWOULDBLOCK) +00095 if (lbm_errnum() == LBM_EWOULDBLOCK)@@ -202,15 +175,14 @@Check Flight Size
and that it cannot send until messages are decalred stable, or not-stable in the event of timeout or store loss.-00095 if (lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL) == 0) -00096 { -00097 /* Check to see if the inflight counter is equal to the configured flight size */ -00098 if (inflight == DEFAULT_APP_FLIGHT_SIZE) -00099 { -00100 /* Print alert */ -00101 printf("ALERT: Source is blocked on flight size: %d\n", inflight); -00102 } -00103 } +00097 err = lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL); +00098 EX_LBM_CHK(err); +00099 +00100 /* Is inflight counter is equal to the configured flight size? */ +00101 if (inflight == DEFAULT_APP_FLIGHT_SIZE) +00102 { +00103 printf("ALERT: Source is blocked on flight size: %d\n", inflight); +00104 }@@ -218,20 +190,20 @@Includes
Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>@@ -239,29 +211,29 @@Store Configuration XML
This is a store configuration file that can be used to run the umestored binary along with this example application
-00001 <?xml version="1.0" encoding="utf-8" ?> -00002 <ume-store version="1.2"> -00003 <daemon> -00004 <log>DEMO_STORE.log</log> -00005 <web-monitor>*:8080/web-monitor> -00006 </daemon> -00007 <stores> -00008 <store name="DEMO_STORE" port="29999"> -00009 <ume-attributes> -00010 <option name="disk-cache-directory" value="cache" type="store"/> -00011 <option name="disk-state-directory" value="state" type="store"/> -00012 <option name="context-name" value="DEMO_STORE"/> -00013 </ume-attributes> -00014 <topics> -00015 <topic pattern=".*" type="PCRE"> -00016 <ume-attributes> -00017 <option name="repository-type" value="disk" type="store"/> -00018 </ume-attributes> -00019 </topic> -00020 </topics> -00021 </store> -00022 </stores> -00023 </ume-store> +00001 <?xml version="1.0" encoding="utf-8" ?> +00002 <ume-store version="1.2"> +00003 <daemon> +00004 <log>DEMO_STORE.log</log> +00005 <web-monitor>*:8080/web-monitor> +00006 </daemon> +00007 <stores> +00008 <store name="DEMO_STORE" port="29999"> +00009 <ume-attributes> +00010 <option name="disk-cache-directory" value="cache" type="store"/> +00011 <option name="disk-state-directory" value="state" type="store"/> +00012 <option name="context-name" value="DEMO_STORE"/> +00013 </ume-attributes> +00014 <topics> +00015 <topic pattern=".*" type="PCRE"> +00016 <ume-attributes> +00017 <option name="repository-type" value="disk" type="store"/> +00018 </ume-attributes> +00019 </topic> +00020 </topics> +00021 </store> +00022 </stores> +00023 </ume-store>diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.slsrc b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.slsrc deleted file mode 100644 index e8846cc..0000000 --- a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.slsrc +++ /dev/null @@ -1,127 +0,0 @@ -/* Code Disclaimer? */ - -/* =semlit,block,includes=*/ -#include- -#if defined(_MSC_VER) -/* Windows-only includes */ -#include -#define SLEEP(s) Sleep((s)*1000) -#else -/* Unix-only includes */ -#include -#include -#define SLEEP(s) sleep(s) -#endif - -#include -/* =semlit,endblock,includes=*/ - -/* =semlit,block,default_flight=*/ -#define DEFAULT_APP_FLIGHT_SIZE 500 /* Used for checking flight size */ -/* =semlit,endblock,default_flight=*/ - -main() -{ - /* =semlit,block,variables=*/ - lbm_context_t *ctx; /* Context object */ - lbm_topic_t *topic; /* Topic object */ - lbm_src_t *src; /* Source object */ - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int inflight; /* Object used for checking inflight counters */ - char flight[4]; - int err; /* Used for checking API return codes */ - /* =semlit,endblock,variables=*/ - -#if defined(_WIN32) - /* 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 - - /* =semlit,block,init_create_context=*/ - if (lbm_context_attr_create(&cattr) != 0) - { - fprintf(stderr, "lbm_context_attr_create: %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); - } - /* =semlit,endblock,init_create_context=*/ - - /* =semlit,block,init_create_source=*/ - if (lbm_src_topic_attr_create(&tattr) != 0) - { - fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); - exit(1); - } - - sprintf(flight, "%d", DEFAULT_APP_FLIGHT_SIZE); - if (lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight) != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } - - /* Assuming there is a store running on the localhost at port 29999 */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } - - err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); - if (err) - { - printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - - err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - if (err) - { - printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - /* =semlit,endblock,init_create_source=*/ - - /* =semlit,block,main_send_loop=*/ - while(1) - /* =semlit,endblock,main_send_loop=*/ - { - /* =semlit,block,src_send=*/ - if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) - /* =semlit,endblock,src_send=*/ - { - /* =semlit,block,check_send_error=*/ - if (lbm_errnum() == LBM_EWOULDBLOCK) - /* =semlit,endblock,check_send_error=*/ - { - /* =semlit,block,get_flight=*/ - if (lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL) == 0) - { - /* Check to see if the inflight counter is equal to the configured flight size */ - if (inflight == DEFAULT_APP_FLIGHT_SIZE) - { - /* Print alert */ - printf("ALERT: Source is blocked on flight size: %d\n", inflight); - } - } - /* =semlit,endblock,get_flight=*/ - } - } - } -} - - diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_c.slsrc b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_c.slsrc new file mode 100644 index 0000000..5d998eb --- /dev/null +++ b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_c.slsrc @@ -0,0 +1,128 @@ +/* check_flight_size_ewouldblock.c - see http://ultramessaging.github.io/UMExamples/check_flight_size_ewouldblock/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + +/* =semlit,block,includes=*/ +#include + +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define SLEEP(s) Sleep((s)*1000) +#else +/* Unix-only includes */ +#include +#include +#define SLEEP(s) sleep(s) +#endif + +#include +/* =semlit,endblock,includes=*/ + +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + +/* =semlit,block,default_flight=*/ +#define DEFAULT_APP_FLIGHT_SIZE 500 /* Used for checking flight size */ +/* =semlit,endblock,default_flight=*/ + + +int main(int argc, char **argv) +{ + /* =semlit,block,variables=*/ + lbm_context_t *ctx; /* Context object */ + lbm_topic_t *topic; /* Topic object */ + lbm_src_t *src; /* Source object */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + int inflight; /* Object used for checking inflight counters */ + char flight[4]; + int err; + /* =semlit,endblock,variables=*/ + +#if defined(_WIN32) + /* 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 + + /* =semlit,block,init_create_context=*/ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,init_create_context=*/ + + /* =semlit,block,init_create_source=*/ + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); + + sprintf(flight, "%d", DEFAULT_APP_FLIGHT_SIZE); + err = lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight); + EX_LBM_CHK(err); + + /* Assuming there is a store running on the localhost at port 29999 */ + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); + EX_LBM_CHK(err); + + err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); + EX_LBM_CHK(err); + + err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,init_create_source=*/ + + /* =semlit,block,main_send_loop=*/ + while(1) + /* =semlit,endblock,main_send_loop=*/ + { + /* =semlit,block,src_send=*/ + err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); + if (err == LBM_FAILURE) + /* =semlit,endblock,src_send=*/ + { + /* =semlit,block,check_send_error=*/ + if (lbm_errnum() == LBM_EWOULDBLOCK) + /* =semlit,endblock,check_send_error=*/ + { + /* =semlit,block,get_flight=*/ + err = lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL); + EX_LBM_CHK(err); + + /* Is inflight counter is equal to the configured flight size? */ + if (inflight == DEFAULT_APP_FLIGHT_SIZE) + { + printf("ALERT: Source is blocked on flight size: %d\n", inflight); + } + /* =semlit,endblock,get_flight=*/ + } + } + } + + return 0; +} /* main */ diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.slsrc.html b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_c.slsrc.html similarity index 52% rename from check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.slsrc.html rename to check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_c.slsrc.html index 2954bcb..8ae62cb 100644 --- a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock.slsrc.html +++ b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_c.slsrc.html @@ -18,76 +18,76 @@ diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store.slsrc b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store_xml.slsrc similarity index 100% rename from check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store.slsrc rename to check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store_xml.slsrc diff --git a/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store.slsrc.html b/check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store_xml.slsrc.html similarity index 100% rename from check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store.slsrc.html rename to check_flight_size_ewouldblock/c/check_flight_size_ewouldblock_store_xml.slsrc.html diff --git a/clean_shutdown/c/clean_shutdown.c b/clean_shutdown/c/clean_shutdown.c index ca2ad80..5a929a6 100644 --- a/clean_shutdown/c/clean_shutdown.c +++ b/clean_shutdown/c/clean_shutdown.c @@ -1,6 +1,26 @@ -/* Code Disclaimer? */ +/* clean_shutdown.c - see http://ultramessaging.github.io/UMExamples/clean_shutdown/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 -00018 +00018 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 00036 00037 00038 00039 00040 00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 00073 00074 00075 @@ -103,15 +103,15 @@ 00085 00086 00087 -00088 -00089 -00090 -00091 -00092 -00093 +00088 +00089 +00090 +00091 +00092 +00093 00094 -00095 -00096 +00095 +00096 00097 00098 00099 @@ -119,13 +119,33 @@ 00101 00102 00103 -00104 +00104 00105 00106 00107 00108 00109 - /* Code Disclaimer? */ +00110 + /* check_flight_size_ewouldblock.c - see http://ultramessaging.github.io/UMExamples/check_flight_size_ewouldblock/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -142,18 +162,27 @@ #include <lbm/lbm.h> + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + #define DEFAULT_APP_FLIGHT_SIZE 500 /* Used for checking flight size */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_topic_t *topic; /* Topic object */ - lbm_src_t *src; /* Source object */ - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int inflight; /* Object used for checking inflight counters */ + lbm_context_t *ctx; /* Context object */ + lbm_topic_t *topic; /* Topic object */ + lbm_src_t *src; /* Source object */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + int inflight; /* Object used for checking inflight counters */ char flight[4]; - int err; /* Used for checking API return codes */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -166,74 +195,47 @@ } #endif - if (lbm_context_attr_create(&cattr) != 0) - { - fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - - if (lbm_src_topic_attr_create(&tattr) != 0) - { - fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); sprintf(flight, "%d", DEFAULT_APP_FLIGHT_SIZE); - if (lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight) != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_flight_size", flight); + EX_LBM_CHK(err); /* Assuming there is a store running on the localhost at port 29999 */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); + EX_LBM_CHK(err); err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); - if (err) - { - printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - if (err) - { - printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); while(1) { - if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); + if (err == LBM_FAILURE) { if (lbm_errnum() == LBM_EWOULDBLOCK) - { - if (lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL) == 0) + { + err = lbm_src_get_inflight(src, LBM_FLIGHT_SIZE_TYPE_UME, &inflight, NULL, NULL); + EX_LBM_CHK(err); + + /* Is inflight counter is equal to the configured flight size? */ + if (inflight == DEFAULT_APP_FLIGHT_SIZE) { - /* Check to see if the inflight counter is equal to the configured flight size */ - if (inflight == DEFAULT_APP_FLIGHT_SIZE) - { - /* Print alert */ - printf("ALERT: Source is blocked on flight size: %d\n", inflight); - } + printf("ALERT: Source is blocked on flight size: %d\n", inflight); } } } } - } - + return 0; + } /* main */ +#include #if defined(_MSC_VER) /* Windows-only includes */ @@ -18,13 +38,14 @@ int cleanup = 0; /* Example error checking macro. Include after each UM call. */ - #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ - } while (0) +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + #if defined(_WIN32) DWORD WINAPI eq_thread(void *arg) @@ -45,13 +66,13 @@ void *eq_thread(void *arg) if (cleanup) break; } -} + return 0; +} /* eq_thread */ + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: printf("LBM_MSG_DATA received\n"); @@ -59,44 +80,41 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } cleanup = 1; -} + return 0; +} /* rcv_handle_msg */ + -main() +int main(int argc, char **argv) { lbm_context_t *ctx; /* pointer to context object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ lbm_topic_t *stopic; /* Source Topic object */ lbm_src_t *src; /* Source object */ lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ lbm_topic_t *rtopic; /* Receiver Topic object */ lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ - int err; /* return status of lbm functions (true=error) */ + int err; #if defined(_WIN32) - HANDLE wthrdh; + HANDLE wthrdh; #else - pthread_t pthid; + pthread_t pthid; #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); - } + /* 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 err = lbm_event_queue_create(&evq, NULL, NULL, NULL); EX_LBM_CHK(err); - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); @@ -118,15 +136,15 @@ main() EX_LBM_CHK(err); #if defined(_WIN32) - if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { - fprintf(stderr, "could not create thread\n"); - exit(1); - } + if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { + fprintf(stderr, "could not create thread\n"); + exit(1); + } #else - if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { - fprintf(stderr, "could not spawn thread\n"); - exit(1); - } + if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { + fprintf(stderr, "could not spawn thread\n"); + exit(1); + } #endif /* _WIN32 */ SLEEP(1); @@ -139,17 +157,24 @@ main() SLEEP(1); } - lbm_event_dispatch_unblock(evq); + err = lbm_event_dispatch_unblock(evq); + EX_LBM_CHK(err); #if defined(_WIN32) - WaitForSingleObject(wthrdh, INFINITE); + WaitForSingleObject(wthrdh, INFINITE); #else - pthread_join(pthid, NULL); + pthread_join(pthid, NULL); #endif /* _WIN32 */ - lbm_rcv_delete(rcv); - lbm_src_delete(src); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); -} + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); + + return 0; +} /* main */ diff --git a/clean_shutdown/c/clean_shutdown.sldoc.html b/clean_shutdown/c/clean_shutdown.sldoc.html index 2983d2f..86997bc 100644 --- a/clean_shutdown/c/clean_shutdown.sldoc.html +++ b/clean_shutdown/c/clean_shutdown.sldoc.html @@ -36,14 +36,11 @@ Create Event Queue and Context
event queue first.-00093 err = lbm_event_queue_create(&evq, NULL, NULL, NULL); -00094 EX_LBM_CHK(err); -00095 -00096 err = lbm_context_attr_create(&cattr); -00097 EX_LBM_CHK(err); -00098 -00099 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00100 EX_LBM_CHK(err); +00114 err = lbm_event_queue_create(&evq, NULL, NULL, NULL); +00115 EX_LBM_CHK(err); +00116 +00117 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00118 EX_LBM_CHK(err);@@ -52,23 +49,23 @@Create Source and Receiver
later, it is important to delete all sources and receivers before deleting the context.-00102 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); -00103 EX_LBM_CHK(err); -00104 -00105 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq); -00106 EX_LBM_CHK(err); -00107 -00108 err = lbm_src_topic_attr_create(&tattr); -00109 EX_LBM_CHK(err); -00110 -00111 err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); -00112 EX_LBM_CHK(err); -00113 -00114 err = lbm_src_topic_attr_delete(tattr); -00115 EX_LBM_CHK(err); -00116 -00117 err = lbm_src_create(&src, ctx, stopic, NULL, NULL, NULL); -00118 EX_LBM_CHK(err); +00120 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); +00121 EX_LBM_CHK(err); +00122 +00123 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq); +00124 EX_LBM_CHK(err); +00125 +00126 err = lbm_src_topic_attr_create(&tattr); +00127 EX_LBM_CHK(err); +00128 +00129 err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); +00130 EX_LBM_CHK(err); +00131 +00132 err = lbm_src_topic_attr_delete(tattr); +00133 EX_LBM_CHK(err); +00134 +00135 err = lbm_src_create(&src, ctx, stopic, NULL, NULL, NULL); +00136 EX_LBM_CHK(err);@@ -77,17 +74,17 @@Spawn Event Queue Thread
application use case as users would want an independent thread that only processes events (like messages) for better performace.-00120 #if defined(_WIN32) -00121 if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { -00122 fprintf(stderr, "could not create thread\n"); -00123 exit(1); -00124 } -00125 #else -00126 if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { -00127 fprintf(stderr, "could not spawn thread\n"); -00128 exit(1); -00129 } -00130 #endif /* _WIN32 */ +00138 #if defined(_WIN32) +00139 if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { +00140 fprintf(stderr, "could not create thread\n"); +00141 exit(1); +00142 } +00143 #else +00144 if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { +00145 fprintf(stderr, "could not spawn thread\n"); +00146 exit(1); +00147 } +00148 #endif /* _WIN32 */@@ -97,15 +94,15 @@Sleep, Send Message, and Wait
thread will simply wait for the receiver to receive the message on the event queue.-00132 SLEEP(1); -00133 -00134 err = lbm_src_send(src, "hello", 5, LBM_MSG_FLUSH); -00135 EX_LBM_CHK(err); -00136 -00137 /* Wait */ -00138 while (!cleanup) { -00139 SLEEP(1); -00140 } +00150 SLEEP(1); +00151 +00152 err = lbm_src_send(src, "hello", 5, LBM_MSG_FLUSH); +00153 EX_LBM_CHK(err); +00154 +00155 /* Wait */ +00156 while (!cleanup) { +00157 SLEEP(1); +00158 }@@ -115,13 +112,14 @@Unblock Event Queue and Kill Thread
thread before continuing.-00142 lbm_event_dispatch_unblock(evq); -00143 -00144 #if defined(_WIN32) -00145 WaitForSingleObject(wthrdh, INFINITE); -00146 #else -00147 pthread_join(pthid, NULL); -00148 #endif /* _WIN32 */ +00160 err = lbm_event_dispatch_unblock(evq); +00161 EX_LBM_CHK(err); +00162 +00163 #if defined(_WIN32) +00164 WaitForSingleObject(wthrdh, INFINITE); +00165 #else +00166 pthread_join(pthid, NULL); +00167 #endif /* _WIN32 */@@ -130,10 +128,14 @@Delete Objects in the Correct Order
has been closed. The application can now delete all UM objects in the correct order.
-00150 lbm_rcv_delete(rcv); -00151 lbm_src_delete(src); -00152 lbm_context_delete(ctx); -00153 lbm_event_queue_delete(evq); +00169 err = lbm_rcv_delete(rcv); +00170 EX_LBM_CHK(err); +00171 err = lbm_src_delete(src); +00172 EX_LBM_CHK(err); +00173 err = lbm_context_delete(ctx); +00174 EX_LBM_CHK(err); +00175 err = lbm_event_queue_delete(evq); +00176 EX_LBM_CHK(err);@@ -143,13 +145,13 @@Error Checking
print a message and exit the program:-00021 #define EX_LBM_CHK(err) do { \ -00022 if ((err) < 0) { \ -00023 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ -00024 __FILE__, __LINE__, lbm_errmsg()); \ -00025 exit(1); \ -00026 } \ -00027 } while (0) +00041 #define EX_LBM_CHK(err) do { \ +00042 if ((err) < 0) { \ +00043 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ +00044 __FILE__, __LINE__, lbm_errmsg()); \ +00045 exit(1); \ +00046 } \ +00047 } while (0)@@ -166,20 +168,21 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 #include <pthread.h> +00024 +00025 #if defined(_MSC_VER) +00026 /* Windows-only includes */ +00027 #include <winsock2.h> +00028 #define SLEEP(s) Sleep((s)*1000) +00029 #else +00030 /* Unix-only includes */ +00031 #include <stdlib.h> +00032 #include <unistd.h> +00033 #define SLEEP(s) sleep(s) +00034 #endif +00035 +00036 #include <lbm/lbm.h>@@ -187,16 +190,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00082 #if defined(_MSC_VER) -00083 /* windows-specific code */ -00084 WSADATA wsadata; -00085 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00086 if (wsStat != 0) -00087 { -00088 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00089 exit(1); -00090 } -00091 #endif +00103 #if defined(_MSC_VER) +00104 /* windows-specific code */ +00105 WSADATA wsadata; +00106 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00107 if (wsStat != 0) +00108 { +00109 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00110 exit(1); +00111 } +00112 #endifdiff --git a/clean_shutdown/c/clean_shutdown_c.slsrc b/clean_shutdown/c/clean_shutdown_c.slsrc index 58a6e44..981958f 100644 --- a/clean_shutdown/c/clean_shutdown_c.slsrc +++ b/clean_shutdown/c/clean_shutdown_c.slsrc @@ -1,7 +1,27 @@ -/* Code Disclaimer? */ +/* clean_shutdown.c - see http://ultramessaging.github.io/UMExamples/clean_shutdown/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include+#include #if defined(_MSC_VER) /* Windows-only includes */ @@ -21,15 +41,16 @@ int cleanup = 0; /* Example error checking macro. Include after each UM call. */ /* =semlit,block,error_check=*/ - #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ - } while (0) +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) /* =semlit,endblock,error_check=*/ + /* =semlit,block,eq_thread=*/ #if defined(_WIN32) DWORD WINAPI eq_thread(void *arg) @@ -50,14 +71,14 @@ void *eq_thread(void *arg) if (cleanup) break; } -} + return 0; +} /* eq_thread */ /* =semlit,endblock,eq_thread=*/ + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: printf("LBM_MSG_DATA received\n"); @@ -65,47 +86,44 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } cleanup = 1; -} + return 0; +} /* rcv_handle_msg */ + -main() +int main(int argc, char **argv) { lbm_context_t *ctx; /* pointer to context object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ lbm_topic_t *stopic; /* Source Topic object */ lbm_src_t *src; /* Source object */ lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ lbm_topic_t *rtopic; /* Receiver Topic object */ lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ - int err; /* return status of lbm functions (true=error) */ + int err; #if defined(_WIN32) - HANDLE wthrdh; + HANDLE wthrdh; #else - pthread_t pthid; + pthread_t pthid; #endif /* _WIN32 */ - - /* =semlit,block,windows=*/ + /* =semlit,block,windows=*/ #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); - } + /* 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 - /* =semlit,endblock,windows=*/ + /* =semlit,endblock,windows=*/ /* =semlit,block,eq_ctx_create= */ err = lbm_event_queue_create(&evq, NULL, NULL, NULL); EX_LBM_CHK(err); - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); /* =semlit,endblock,eq_ctx_create=*/ @@ -129,19 +147,19 @@ main() EX_LBM_CHK(err); /* =semlit,endblock,src_rcv_create=*/ - /* =semlit,block,spawn_thread=*/ + /* =semlit,block,spawn_thread=*/ #if defined(_WIN32) - if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { - fprintf(stderr, "could not create thread\n"); - exit(1); - } + if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { + fprintf(stderr, "could not create thread\n"); + exit(1); + } #else - if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { - fprintf(stderr, "could not spawn thread\n"); - exit(1); - } + if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { + fprintf(stderr, "could not spawn thread\n"); + exit(1); + } #endif /* _WIN32 */ - /* =semlit,endblock,spawn_thread=*/ + /* =semlit,endblock,spawn_thread=*/ /* =semlit,block,wait_and_send=*/ SLEEP(1); @@ -156,20 +174,27 @@ main() /* =semlit,endblock,wait_and_send=*/ /* =semlit,block,unblock_join=*/ - lbm_event_dispatch_unblock(evq); + err = lbm_event_dispatch_unblock(evq); + EX_LBM_CHK(err); #if defined(_WIN32) - WaitForSingleObject(wthrdh, INFINITE); + WaitForSingleObject(wthrdh, INFINITE); #else - pthread_join(pthid, NULL); + pthread_join(pthid, NULL); #endif /* _WIN32 */ /* =semlit,endblock,unblock_join=*/ /* =semlit,block,delete=*/ - lbm_rcv_delete(rcv); - lbm_src_delete(src); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); /* =semlit,endblock,delete=*/ -} + + return 0; +} /* main */ diff --git a/clean_shutdown/c/clean_shutdown_c.slsrc.html b/clean_shutdown/c/clean_shutdown_c.slsrc.html index 90d55f0..b375be8 100644 --- a/clean_shutdown/c/clean_shutdown_c.slsrc.html +++ b/clean_shutdown/c/clean_shutdown_c.slsrc.html @@ -18,74 +18,74 @@ diff --git a/context_create/c/context_create_c.slsrc b/context_create/c/context_create_c.slsrc index 5baaf30..3d6d5fc 100644 --- a/context_create/c/context_create_c.slsrc +++ b/context_create/c/context_create_c.slsrc @@ -18,7 +18,7 @@ /* =semlit,endblock,includes=*/ /* =semlit,block,main=*/ -main() +int main(int argc, char **argv) { /* =semlit,block,declare=*/ lbm_context_t *ctx; /* pointer to context object */ @@ -57,5 +57,6 @@ main() WSACleanup(); #endif /* =semlit,endblock,winclean=*/ + return 0; } /* =semlit,endblock,main= */ diff --git a/dotnet_index.html b/dotnet_index.html index c2883bd..04efa6f 100644 --- a/dotnet_index.html +++ b/dotnet_index.html @@ -1,9 +1,18 @@ - - -
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 00019 00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 00071 00072 00073 @@ -97,83 +97,128 @@ 00079 00080 00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 00092 -00093 -00094 -00095 -00096 -00097 -00098 -00099 -00100 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 00101 -00102 -00103 -00104 -00105 -00106 -00107 -00108 -00109 -00110 -00111 -00112 -00113 -00114 -00115 -00116 -00117 -00118 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 00119 -00120 -00121 -00122 -00123 -00124 -00125 -00126 -00127 -00128 -00129 -00130 -00131 -00132 -00133 -00134 -00135 -00136 -00137 -00138 -00139 -00140 -00141 -00142 -00143 -00144 -00145 -00146 -00147 -00148 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 00149 -00150 -00151 -00152 -00153 -00154 -00155 - /* Code Disclaimer? */ +00150 +00151 +00152 +00153 +00154 +00155 +00156 +00157 +00158 +00159 +00160 +00161 +00162 +00163 +00164 +00165 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 + /* clean_shutdown.c - see http://ultramessaging.github.io/UMExamples/clean_shutdown/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> + #include <pthread.h> #if defined(_MSC_VER) /* Windows-only includes */ @@ -191,13 +236,14 @@ int cleanup = 0; /* Example error checking macro. Include after each UM call. */ - #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ - } while (0) + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + #if defined(_WIN32) DWORD WINAPI eq_thread(void *arg) @@ -218,13 +264,13 @@ if (cleanup) break; } - } + return 0; + } /* eq_thread */ + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: printf("LBM_MSG_DATA received\n"); @@ -232,44 +278,41 @@ } cleanup = 1; - } + return 0; + } /* rcv_handle_msg */ + - main() + int main(int argc, char **argv) { lbm_context_t *ctx; /* pointer to context object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ lbm_topic_t *stopic; /* Source Topic object */ lbm_src_t *src; /* Source object */ lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ lbm_topic_t *rtopic; /* Receiver Topic object */ lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ - int err; /* return status of lbm functions (true=error) */ + int err; #if defined(_WIN32) - HANDLE wthrdh; + HANDLE wthrdh; #else - pthread_t pthid; + pthread_t pthid; #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); - } + /* 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 err = lbm_event_queue_create(&evq, NULL, NULL, NULL); EX_LBM_CHK(err); - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); @@ -291,15 +334,15 @@ EX_LBM_CHK(err); #if defined(_WIN32) - if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { - fprintf(stderr, "could not create thread\n"); - exit(1); - } + if ((wthrdh = CreateThread(NULL, 0, eq_thread, evq, 0, NULL)) == NULL) { + fprintf(stderr, "could not create thread\n"); + exit(1); + } #else - if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { - fprintf(stderr, "could not spawn thread\n"); - exit(1); - } + if (pthread_create(&pthid, NULL, eq_thread, evq) != 0) { + fprintf(stderr, "could not spawn thread\n"); + exit(1); + } #endif /* _WIN32 */ SLEEP(1); @@ -312,19 +355,26 @@ SLEEP(1); } - lbm_event_dispatch_unblock(evq); + err = lbm_event_dispatch_unblock(evq); + EX_LBM_CHK(err); #if defined(_WIN32) - WaitForSingleObject(wthrdh, INFINITE); + WaitForSingleObject(wthrdh, INFINITE); #else - pthread_join(pthid, NULL); + pthread_join(pthid, NULL); #endif /* _WIN32 */ - lbm_rcv_delete(rcv); - lbm_src_delete(src); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); - } + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); + + return 0; + } /* main */ UMExamples - C#/.NET Language - +UMExamples - C#/.NET Language + + - + ++diff --git a/dump_attributes/c/dump_attributes.c b/dump_attributes/c/dump_attributes.c index 1cc9546..9e20201 100644 --- a/dump_attributes/c/dump_attributes.c +++ b/dump_attributes/c/dump_attributes.c @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* dump_attributes.c - see http://ultramessaging.github.io/UMExamples/dump_attributes/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include++
+Welcome to UMExamples +
+ +© Copyright Informatica LLC 2004-2020. +
+C#/.NET Examples
Examples written in C#/.NET.
@@ -40,5 +49,36 @@Examples
source_notify_callbacks C Java C#/.NET A sample application that demonstrates how to configure and code the source_notification_callback feature for receivers + + ump_receiver_callbacks C Java C#/.NET A sample application that handles all UMP receiver callbacks and logs important data
+ +Notices
+This software and documentation are provided only under a separate license +agreement containing restrictions on use and disclosure. +No part of this document may be reproduced or transmitted in any form, +by any means (electronic, photocopying, recording or otherwise) +without prior consent of Informatica LLC. + +
A current list of Informatica trademarks is available on the web at +https://www.informatica.com/trademarks.html. + +
Portions of this software and/or documentation are subject to copyright +held by third parties. +Required third party notices are included with the product. + +
Informatica software is protected by patents as detailed at +https://www.informatica.com/legal/patents.html. + +
The information in this documentation is subject to change without notice. +If you find any problems in this documentation, please report them to us in +writing at Informatica LLC 2100 Seaport Blvd. Redwood City, CA 94063. + +
Informatica products are warranted according to the terms and conditions +of the agreements under which they are provided. +
INFORMATICA LLC PROVIDES THE INFORMATION IN THIS DOCUMENT "AS IS" WITHOUT +WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT ANY WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OR +CONDITION OF NON-INFRINGEMENT. +@@ -15,23 +34,32 @@ #include -main() +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + +int main(int argc, char **argv) { - 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_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_config_option_t *configs_option_ptr; /* pointer to configuration options returned from lib*/ - 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) */ - int entries; /* Int used to count number of config entries */ - int idx; /* Int used to iterate across config entries */ - + lbm_uint16_t res_port; /* Int to set resolver port */ + lbm_uint16_t des_port; /* Int to set lbtrm destination port */ + int entries; /* Int used to count number of config entries */ + int idx; /* Int used to iterate across config entries */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -45,116 +73,70 @@ main() #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); - } + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* Creating the context */ err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + err = lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr_1); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } - /* each lbm object (ctx, src, rcv) has a different number of configuration */ - /* attributes. To allocate the array, call the corresponding *_option_size */ - /* function and allocate enough memory to contain the return strings */ + EX_LBM_CHK(err); + /* each lbm object (ctx, src, rcv) has a different number of configuration + * attributes. To allocate the array, call the corresponding *_option_size + * function and allocate enough memory to contain the return strings. */ entries = lbm_context_attr_option_size(); configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); /* Get the attributes for the context */ - if (LBM_FAILURE == lbm_context_dump(ctx, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_context_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_context_dump(ctx, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -163,6 +145,7 @@ main() /* done with context attributes so free the allocated memory */ free(configs_option_ptr); + /* each lbm object (ctx, src, rcv) has a different number of configuration */ /* options to allocate the array, call the corresponding *_option_size */ /* function and allocate enough memory to contain the return strings */ @@ -170,11 +153,8 @@ main() configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); /* Get the attributes for the first source */ - if (LBM_FAILURE == lbm_src_topic_dump(src_1, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_src_topic_dump(src_1, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -184,11 +164,8 @@ main() /* note that configs_option_ptr can be reused for multiple sources without being freed. */ /* Get the attributes for the second source */ - if (LBM_FAILURE == lbm_src_topic_dump(src_2, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_src_topic_dump(src_2, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -197,17 +174,24 @@ main() /* done with source attributes so free the allocated memory */ free(configs_option_ptr); + /* Delete the first and second source topic attribute objects */ - lbm_src_topic_attr_delete(tattr_1); - lbm_src_topic_attr_delete(tattr_2); + err = lbm_src_topic_attr_delete(tattr_1); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_delete(tattr_2); + EX_LBM_CHK(err); /* 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); + err = lbm_src_delete(src_1); + EX_LBM_CHK(err); + err = lbm_src_delete(src_2); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/dump_attributes/c/dump_attributes.sldoc.html b/dump_attributes/c/dump_attributes.sldoc.html index df37e8d..700f74f 100644 --- a/dump_attributes/c/dump_attributes.sldoc.html +++ b/dump_attributes/c/dump_attributes.sldoc.html @@ -34,43 +34,26 @@ Initialization
object is used to configure a sources attributes.-00079 /* Initializing the source attribute object */ -00080 if (lbm_src_topic_attr_create(&tattr_1) != 0) -00081 { -00082 fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); -00083 exit(1); -00084 } -00085 -00086 /* Setting the transport via the source topic string method */ -00087 if (lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm") != 0) -00088 { -00089 fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); -00090 exit(1); -00091 } -00092 -00093 /* Setting the lbtrm destination port via the direct value set method */ -00094 des_port = 14001; -00095 if (lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)) != 0) -00096 { -00097 fprintf(stderr, "lbm_src_topic_attr_setopt:transport_lbtrm_destination_port: %s\n", lbm_errmsg()); -00098 exit(1); -00099 } -00100 -00101 /* Allocating the topic */ -00102 err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); -00103 if (err) -00104 { -00105 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00106 exit(1); -00107 } -00108 -00109 /* Creating the source */ -00110 err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); -00111 if (err) -00112 { -00113 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00114 exit(1); -00115 } +00095 /* Initializing the source attribute object */ +00096 err = lbm_src_topic_attr_create(&tattr_1); +00097 EX_LBM_CHK(err); +00098 +00099 /* Setting the transport via the source topic string method */ +00100 err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); +00101 EX_LBM_CHK(err); +00102 +00103 /* Setting the lbtrm destination port via the direct value set method */ +00104 des_port = 14001; +00105 err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); +00106 EX_LBM_CHK(err); +00107 +00108 /* Allocating the topic */ +00109 err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); +00110 EX_LBM_CHK(err); +00111 +00112 /* Creating the source */ +00113 err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); +00114 EX_LBM_CHK(err);@@ -81,36 +64,22 @@Initialization
in the attributes that will be dumped later.-00116 /* Initialized the second source attributes as a copy of the first */ -00117 if (lbm_src_topic_attr_dup(&tattr_2, tattr_1) != 0) -00118 { -00119 fprintf(stderr, "lbm_src_topic_attr_dup: %s\n", lbm_errmsg()); -00120 exit(1); -00121 } -00122 -00123 /* Now modify the destination port for this second source to put the publisher on a different transport */ -00124 des_port = 14002; -00125 if (lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)) != 0) -00126 { -00127 fprintf(stderr, "lbm_src_topic_attr_setopt:transport_lbtrm_destination_port: %s\n", lbm_errmsg()); -00128 exit(1); -00129 } -00130 -00131 /* Allocating the second topic */ -00132 err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); -00133 if (err) -00134 { -00135 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00136 exit(1); -00137 } -00138 -00139 /* Creating the source */ -00140 err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); -00141 if (err) -00142 { -00143 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00144 exit(1); -00145 } +00115 /* Initialized the second source attributes as a copy of the first */ +00116 err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); +00117 EX_LBM_CHK(err); +00118 +00119 /* Now modify the destination port for this second source to put the publisher on a different transport */ +00120 des_port = 14002; +00121 err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); +00122 EX_LBM_CHK(err); +00123 +00124 /* Allocating the second topic */ +00125 err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); +00126 EX_LBM_CHK(err); +00127 +00128 /* Creating the source */ +00129 err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); +00130 EX_LBM_CHK(err);@@ -131,26 +100,23 @@Dump Context Attributes
numbers of attributes.-00146 /* each lbm object (ctx, src, rcv) has a different number of configuration */ -00147 /* attributes. To allocate the array, call the corresponding *_option_size */ -00148 /* function and allocate enough memory to contain the return strings */ -00149 entries = lbm_context_attr_option_size(); -00150 configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); -00151 -00152 /* Get the attributes for the context */ -00153 if (LBM_FAILURE == lbm_context_dump(ctx, &entries, configs_option_ptr)) -00154 { -00155 fprintf(stderr, "lbm_context_dump error: %s\n", lbm_errmsg()); -00156 return; -00157 } -00158 -00159 /* iterate through the returned array and print each option */ -00160 for (idx = 0; idx < entries; ++idx) { -00161 printf("%s[%d]: %s = %s\n", configs_option_ptr[idx].type, idx, configs_option_ptr[idx].oname, configs_option_ptr[idx].val); -00162 } -00163 -00164 /* done with context attributes so free the allocated memory */ -00165 free(configs_option_ptr); +00131 /* each lbm object (ctx, src, rcv) has a different number of configuration +00132 * attributes. To allocate the array, call the corresponding *_option_size +00133 * function and allocate enough memory to contain the return strings. */ +00134 entries = lbm_context_attr_option_size(); +00135 configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); +00136 +00137 /* Get the attributes for the context */ +00138 err = lbm_context_dump(ctx, &entries, configs_option_ptr); +00139 EX_LBM_CHK(err); +00140 +00141 /* iterate through the returned array and print each option */ +00142 for (idx = 0; idx < entries; ++idx) { +00143 printf("%s[%d]: %s = %s\n", configs_option_ptr[idx].type, idx, configs_option_ptr[idx].oname, configs_option_ptr[idx].val); +00144 } +00145 +00146 /* done with context attributes so free the allocated memory */ +00147 free(configs_option_ptr);@@ -167,26 +133,23 @@Dump Source Attributes
Finally, it can be filled by the lbm_*_dump function.-00166 /* each lbm object (ctx, src, rcv) has a different number of configuration */ -00167 /* options to allocate the array, call the corresponding *_option_size */ -00168 /* function and allocate enough memory to contain the return strings */ -00169 entries = lbm_src_topic_attr_option_size(); -00170 configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); -00171 -00172 /* Get the attributes for the first source */ -00173 if (LBM_FAILURE == lbm_src_topic_dump(src_1, &entries, configs_option_ptr)) -00174 { -00175 fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); -00176 return; -00177 } -00178 -00179 /* iterate through the returned array and print each option */ -00180 for (idx = 0; idx < entries; ++idx) { -00181 printf("%s[%d]: %s = %s\n", configs_option_ptr[idx].type, idx, configs_option_ptr[idx].oname, configs_option_ptr[idx].val); -00182 } -00183 -00184 /* note that configs_option_ptr can be reused for multiple sources without being freed. */ -00185 +00149 /* each lbm object (ctx, src, rcv) has a different number of configuration */ +00150 /* options to allocate the array, call the corresponding *_option_size */ +00151 /* function and allocate enough memory to contain the return strings */ +00152 entries = lbm_src_topic_attr_option_size(); +00153 configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); +00154 +00155 /* Get the attributes for the first source */ +00156 err = lbm_src_topic_dump(src_1, &entries, configs_option_ptr); +00157 EX_LBM_CHK(err); +00158 +00159 /* iterate through the returned array and print each option */ +00160 for (idx = 0; idx < entries; ++idx) { +00161 printf("%s[%d]: %s = %s\n", configs_option_ptr[idx].type, idx, configs_option_ptr[idx].oname, configs_option_ptr[idx].val); +00162 } +00163 +00164 /* note that configs_option_ptr can be reused for multiple sources without being freed. */ +00165@@ -197,20 +160,17 @@Dump Source Attributes
no longer be used. Therefore it can & should be freed.-00186 /* Get the attributes for the second source */ -00187 if (LBM_FAILURE == lbm_src_topic_dump(src_2, &entries, configs_option_ptr)) -00188 { -00189 fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); -00190 return; -00191 } -00192 -00193 /* iterate through the returned array and print each option */ -00194 for (idx = 0; idx < entries; ++idx) { -00195 printf("%s[%d]: %s = %s\n", configs_option_ptr[idx].type, idx, configs_option_ptr[idx].oname, configs_option_ptr[idx].val); -00196 } -00197 -00198 /* done with source attributes so free the allocated memory */ -00199 free(configs_option_ptr); +00166 /* Get the attributes for the second source */ +00167 err = lbm_src_topic_dump(src_2, &entries, configs_option_ptr); +00168 EX_LBM_CHK(err); +00169 +00170 /* iterate through the returned array and print each option */ +00171 for (idx = 0; idx < entries; ++idx) { +00172 printf("%s[%d]: %s = %s\n", configs_option_ptr[idx].type, idx, configs_option_ptr[idx].oname, configs_option_ptr[idx].val); +00173 } +00174 +00175 /* done with source attributes so free the allocated memory */ +00176 free(configs_option_ptr);diff --git a/dump_attributes/c/dump_attributes_c.slsrc b/dump_attributes/c/dump_attributes_c.slsrc index 7c5e4de..a63448f 100644 --- a/dump_attributes/c/dump_attributes_c.slsrc +++ b/dump_attributes/c/dump_attributes_c.slsrc @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* dump_attributes.c - see http://ultramessaging.github.io/UMExamples/dump_attributes/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -15,23 +34,32 @@ #include -main() +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + +int main(int argc, char **argv) { - 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_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_config_option_t *configs_option_ptr; /* pointer to configuration options returned from lib*/ - 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) */ - int entries; /* Int used to count number of config entries */ - int idx; /* Int used to iterate across config entries */ - + lbm_uint16_t res_port; /* Int to set resolver port */ + lbm_uint16_t des_port; /* Int to set lbtrm destination port */ + int entries; /* Int used to count number of config entries */ + int idx; /* Int used to iterate across config entries */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -45,121 +73,75 @@ main() #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); - } + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* Creating the context */ err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + err = lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); /*=semlit,block,src_create=*/ /* 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); - } + err = lbm_src_topic_attr_create(&tattr_1); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /*=semlit,endblock,src_create=*/ /*=semlit,block,src_create2=*/ /* 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); - } + err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /*=semlit,endblock,src_create2=*/ /*=semlit,block,dump_ctx_attr=*/ - /* each lbm object (ctx, src, rcv) has a different number of configuration */ - /* attributes. To allocate the array, call the corresponding *_option_size */ - /* function and allocate enough memory to contain the return strings */ + /* each lbm object (ctx, src, rcv) has a different number of configuration + * attributes. To allocate the array, call the corresponding *_option_size + * function and allocate enough memory to contain the return strings. */ entries = lbm_context_attr_option_size(); configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); /* Get the attributes for the context */ - if (LBM_FAILURE == lbm_context_dump(ctx, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_context_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_context_dump(ctx, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -169,6 +151,7 @@ main() /* done with context attributes so free the allocated memory */ free(configs_option_ptr); /*=semlit,endblock,dump_ctx_attr=*/ + /*=semlit,block,dump_src_attr=*/ /* each lbm object (ctx, src, rcv) has a different number of configuration */ /* options to allocate the array, call the corresponding *_option_size */ @@ -177,11 +160,8 @@ main() configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); /* Get the attributes for the first source */ - if (LBM_FAILURE == lbm_src_topic_dump(src_1, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_src_topic_dump(src_1, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -193,11 +173,8 @@ main() /*=semlit,endblock,dump_src_attr=*/ /*=semlit,block,dump_src_attr2=*/ /* Get the attributes for the second source */ - if (LBM_FAILURE == lbm_src_topic_dump(src_2, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_src_topic_dump(src_2, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -207,17 +184,24 @@ main() /* done with source attributes so free the allocated memory */ free(configs_option_ptr); /*=semlit,endblock,dump_src_attr2=*/ + /* Delete the first and second source topic attribute objects */ - lbm_src_topic_attr_delete(tattr_1); - lbm_src_topic_attr_delete(tattr_2); + err = lbm_src_topic_attr_delete(tattr_1); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_delete(tattr_2); + EX_LBM_CHK(err); /* 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); + err = lbm_src_delete(src_1); + EX_LBM_CHK(err); + err = lbm_src_delete(src_2); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/dump_attributes/c/dump_attributes_c.slsrc.html b/dump_attributes/c/dump_attributes_c.slsrc.html index 0651c7f..7901ced 100644 --- a/dump_attributes/c/dump_attributes_c.slsrc.html +++ b/dump_attributes/c/dump_attributes_c.slsrc.html @@ -94,22 +94,22 @@ 00076 00077 00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 00095 00096 00097 @@ -130,7 +130,7 @@ 00112 00113 00114 -00115 +00115 00116 00117 00118 @@ -146,90 +146,93 @@ 00128 00129 00130 -00131 -00132 -00133 -00134 -00135 -00136 -00137 -00138 -00139 -00140 -00141 -00142 -00143 -00144 -00145 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 00146 00147 -00148 -00149 -00150 -00151 -00152 -00153 -00154 -00155 -00156 -00157 -00158 -00159 -00160 -00161 -00162 -00163 -00164 -00165 -00166 -00167 -00168 -00169 -00170 -00171 -00172 -00173 -00174 -00175 -00176 -00177 -00178 -00179 -00180 -00181 -00182 -00183 -00184 -00185 -00186 -00187 -00188 -00189 -00190 -00191 -00192 -00193 -00194 -00195 -00196 -00197 -00198 -00199 -00200 -00201 -00202 -00203 -00204 -00205 -00206 -00207 -00208 -00209 -00210 -00211 -00212 -00213 - /* Example on setting Ultra Messaging attributes */ +00148 +00149 +00150 +00151 +00152 +00153 +00154 +00155 +00156 +00157 +00158 +00159 +00160 +00161 +00162 +00163 +00164 +00165 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 +00181 +00182 +00183 +00184 +00185 +00186 +00187 +00188 +00189 +00190 +00191 +00192 +00193 +00194 +00195 +00196 +00197 + /* dump_attributes.c - see http://ultramessaging.github.io/UMExamples/dump_attributes/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -246,23 +249,32 @@ #include <lbm/lbm.h> - main() + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + + int main(int argc, char **argv) { - 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_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_config_option_t *configs_option_ptr; /* pointer to configuration options returned from lib*/ - 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) */ - int entries; /* Int used to count number of config entries */ - int idx; /* Int used to iterate across config entries */ - + lbm_uint16_t res_port; /* Int to set resolver port */ + lbm_uint16_t des_port; /* Int to set lbtrm destination port */ + int entries; /* Int used to count number of config entries */ + int idx; /* Int used to iterate across config entries */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -276,116 +288,70 @@ #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); - } + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* Creating the context */ err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + err = lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr_1); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } - /* each lbm object (ctx, src, rcv) has a different number of configuration */ - /* attributes. To allocate the array, call the corresponding *_option_size */ - /* function and allocate enough memory to contain the return strings */ + EX_LBM_CHK(err); + /* each lbm object (ctx, src, rcv) has a different number of configuration + * attributes. To allocate the array, call the corresponding *_option_size + * function and allocate enough memory to contain the return strings. */ entries = lbm_context_attr_option_size(); configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); /* Get the attributes for the context */ - if (LBM_FAILURE == lbm_context_dump(ctx, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_context_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_context_dump(ctx, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -394,6 +360,7 @@ /* done with context attributes so free the allocated memory */ free(configs_option_ptr); + /* each lbm object (ctx, src, rcv) has a different number of configuration */ /* options to allocate the array, call the corresponding *_option_size */ /* function and allocate enough memory to contain the return strings */ @@ -401,11 +368,8 @@ configs_option_ptr = malloc(entries * sizeof(lbm_config_option_t)); /* Get the attributes for the first source */ - if (LBM_FAILURE == lbm_src_topic_dump(src_1, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_src_topic_dump(src_1, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -415,11 +379,8 @@ /* note that configs_option_ptr can be reused for multiple sources without being freed. */ /* Get the attributes for the second source */ - if (LBM_FAILURE == lbm_src_topic_dump(src_2, &entries, configs_option_ptr)) - { - fprintf(stderr, "lbm_src_topic_dump error: %s\n", lbm_errmsg()); - return; - } + err = lbm_src_topic_dump(src_2, &entries, configs_option_ptr); + EX_LBM_CHK(err); /* iterate through the returned array and print each option */ for (idx = 0; idx < entries; ++idx) { @@ -428,20 +389,27 @@ /* done with source attributes so free the allocated memory */ free(configs_option_ptr); + /* Delete the first and second source topic attribute objects */ - lbm_src_topic_attr_delete(tattr_1); - lbm_src_topic_attr_delete(tattr_2); + err = lbm_src_topic_attr_delete(tattr_1); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_delete(tattr_2); + EX_LBM_CHK(err); /* 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); + err = lbm_src_delete(src_1); + EX_LBM_CHK(err); + err = lbm_src_delete(src_2); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif - } + return 0; + } /* main */ diff --git a/event_q_rcv/c/event_q_rcv.c b/event_q_rcv/c/event_q_rcv.c index 2072cf1..e24ebc8 100644 --- a/event_q_rcv/c/event_q_rcv.c +++ b/event_q_rcv/c/event_q_rcv.c @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* event_q_rcv.c - see http://ultramessaging.github.io/UMExamples/event_q_rcv/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -15,6 +34,16 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Received message handler (passed into lbm_rcv_create()) */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { @@ -28,17 +57,16 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } return 0; -} +} /* rcv_handle_msg */ + -main() +int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_topic_t *topic_1; /* pointer to topic object */ - lbm_rcv_t *rcv; /* pointer to source object */ - lbm_topic_t *rtopic; /* pointer to receiver topic 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 */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_rcv_t *rcv; /* pointer to source object */ + lbm_topic_t *rtopic; /* pointer to receiver topic object */ + lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -51,57 +79,38 @@ main() } #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); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* Create an event queue and associate it with a callback */ err = lbm_event_queue_create(&evq, NULL, NULL, NULL); - if (err == LBM_FAILURE) { - fprintf(stderr, "lbm_event_queue_create: %s\n", lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - + EX_LBM_CHK(err); + err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); - /* 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) { + /* 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. Normally, + * this is done on a separate, application-created thread. */ + err = lbm_event_dispatch(evq, 10000); + if (err == LBM_FAILURE) { fprintf(stderr, "lbm_event_dispatch returned error: %s\n", lbm_errmsg()); } /* Finished with all LBM functions, delete the source and context object. */ - lbm_rcv_delete(rcv); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/event_q_rcv/c/event_q_rcv.sldoc.html b/event_q_rcv/c/event_q_rcv.sldoc.html index d61a68e..e977850 100644 --- a/event_q_rcv/c/event_q_rcv.sldoc.html +++ b/event_q_rcv/c/event_q_rcv.sldoc.html @@ -22,7 +22,7 @@ Creating the Event Queue
The eventQ is initialized by calling lbm_event_queue_create with no other arguments:
-00073 err = lbm_event_queue_create(&evq, NULL, NULL, NULL); +00087 err = lbm_event_queue_create(&evq, NULL, NULL, NULL);@@ -31,7 +31,7 @@Create a receiver with an event queue.
events will be delivered to the event queue. They will not be processed until lbm_event_dispatch is called with the event queue.-00086 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq); +00093 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq);@@ -41,7 +41,8 @@Processing Events on the Event Queue
the main() thread will execute events for 10 seconds.-00095 if (lbm_event_dispatch(evq, 10000) == LBM_FAILURE) { +00099 err = lbm_event_dispatch(evq, 10000); +00100 if (err == LBM_FAILURE) {@@ -52,9 +53,12 @@Cleanup
queue is empty and no new events are being generated, the event queue can safely be delete()'ed.-00100 lbm_rcv_delete(rcv); -00101 lbm_context_delete(ctx); -00102 lbm_event_queue_delete(evq); +00105 err = lbm_rcv_delete(rcv); +00106 EX_LBM_CHK(err); +00107 err = lbm_context_delete(ctx); +00108 EX_LBM_CHK(err); +00109 err = lbm_event_queue_delete(evq); +00110 EX_LBM_CHK(err);diff --git a/event_q_rcv/c/event_q_rcv_c.slsrc b/event_q_rcv/c/event_q_rcv_c.slsrc index 85c78d3..83d1aa5 100644 --- a/event_q_rcv/c/event_q_rcv_c.slsrc +++ b/event_q_rcv/c/event_q_rcv_c.slsrc @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* event_q_rcv.c - see http://ultramessaging.github.io/UMExamples/event_q_rcv/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -15,6 +34,16 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Received message handler (passed into lbm_rcv_create()) */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { @@ -28,17 +57,16 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } return 0; -} +} /* rcv_handle_msg */ + -main() +int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_topic_t *topic_1; /* pointer to topic object */ - lbm_rcv_t *rcv; /* pointer to source object */ - lbm_topic_t *rtopic; /* pointer to receiver topic 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 */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_rcv_t *rcv; /* pointer to source object */ + lbm_topic_t *rtopic; /* pointer to receiver topic object */ + lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -51,65 +79,46 @@ main() } #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); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* Create an event queue and associate it with a callback */ /* =semlit,block,evq_create= */ err = lbm_event_queue_create(&evq, NULL, NULL, NULL); /* =semlit,endblock,evq_create= */ - if (err == LBM_FAILURE) { - fprintf(stderr, "lbm_event_queue_create: %s\n", lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - + EX_LBM_CHK(err); + /* =semlit,block,rcv_create= */ err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq); /* =semlit,endblock,rcv_create= */ - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); - /* 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. */ + /* 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. Normally, + * this is done on a separate, application-created thread. */ /* =semlit,block,evq_run= */ - if (lbm_event_dispatch(evq, 10000) == LBM_FAILURE) { + err = lbm_event_dispatch(evq, 10000); + if (err == LBM_FAILURE) { /* =semlit,endblock,evq_run= */ fprintf(stderr, "lbm_event_dispatch returned error: %s\n", lbm_errmsg()); } /* Finished with all LBM functions, delete the source and context object. */ /* =semlit,block,evq_close= */ - lbm_rcv_delete(rcv); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); /* =semlit,endblock,evq_close= */ #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/event_q_rcv/c/event_q_rcv_c.slsrc.html b/event_q_rcv/c/event_q_rcv_c.slsrc.html index 7d846ff..bab3822 100644 --- a/event_q_rcv/c/event_q_rcv_c.slsrc.html +++ b/event_q_rcv/c/event_q_rcv_c.slsrc.html @@ -88,7 +88,7 @@ 00070 00071 00072 -00073 +00073 00074 00075 00076 @@ -101,29 +101,57 @@ 00083 00084 00085 -00086 -00087 +00086 +00087 00088 00089 00090 00091 00092 -00093 +00093 00094 -00095 +00095 00096 00097 00098 -00099 -00100 -00101 -00102 +00099 +00100 +00101 +00102 00103 00104 -00105 -00106 -00107 - /* Example on setting Ultra Messaging attributes */ +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 + /* event_q_rcv.c - see http://ultramessaging.github.io/UMExamples/event_q_rcv/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -140,6 +168,16 @@ #include <lbm/lbm.h> + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + /* Received message handler (passed into lbm_rcv_create()) */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { @@ -153,17 +191,16 @@ break; } return 0; - } + } /* rcv_handle_msg */ + - main() + int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_topic_t *topic_1; /* pointer to topic object */ - lbm_rcv_t *rcv; /* pointer to source object */ - lbm_topic_t *rtopic; /* pointer to receiver topic 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 */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_rcv_t *rcv; /* pointer to source object */ + lbm_topic_t *rtopic; /* pointer to receiver topic object */ + lbm_event_queue_t *evq = NULL; /* pointer to eventQ handle */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -176,60 +213,41 @@ } #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); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* Create an event queue and associate it with a callback */ err = lbm_event_queue_create(&evq, NULL, NULL, NULL); - if (err == LBM_FAILURE) { - fprintf(stderr, "lbm_event_queue_create: %s\n", lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - + EX_LBM_CHK(err); + err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, evq); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); - /* 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) { + /* 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. Normally, + * this is done on a separate, application-created thread. */ + err = lbm_event_dispatch(evq, 10000); + if (err == LBM_FAILURE) { fprintf(stderr, "lbm_event_dispatch returned error: %s\n", lbm_errmsg()); } /* Finished with all LBM functions, delete the source and context object. */ - lbm_rcv_delete(rcv); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif - } + return 0; + } /* main */ diff --git a/event_q_src/c/event_q_src.c b/event_q_src/c/event_q_src.c index c65452c..bdb647f 100644 --- a/event_q_src/c/event_q_src.c +++ b/event_q_src/c/event_q_src.c @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* event_q_src.c + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -15,6 +34,16 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Source event handler. the UM library passes all per-source events */ /* back to the application. This will by default execute on the context */ /* thread. Therefore there should be no blocking calls made. If you must */ @@ -39,17 +68,17 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) break; } return 0; -} +} /* handle_src_event */ + -main() +int main(int argc, char **argv) { 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 */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -62,68 +91,48 @@ main() } #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); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + err = lbm_event_queue_create(&evq, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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) { + err = lbm_event_dispatch(evq, 10000); + if (err == 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); + err = lbm_src_topic_attr_delete(tattr); + EX_LBM_CHK(err); /* Finished with all LBM functions, delete the source and context object. */ - lbm_src_delete(src); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); + #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/event_q_src/c/event_q_src.sldoc.html b/event_q_src/c/event_q_src.sldoc.html index e11d44a..c54e612 100644 --- a/event_q_src/c/event_q_src.sldoc.html +++ b/event_q_src/c/event_q_src.sldoc.html @@ -22,7 +22,7 @@ Creating the Event Queue
The easiest way to creant an event queue is to initialize it by calling lbm_event_queue_create with no arguments.
-00099 if (lbm_event_queue_create(&evq, NULL, NULL, NULL) == LBM_FAILURE) { +00107 err = lbm_event_queue_create(&evq, NULL, NULL, NULL);@@ -31,7 +31,7 @@Create a source with an event queue.
events will be delivered to the event queue. They will not be processed until the event queue is run by calling lbm_event_dispatch.-00105 err = lbm_src_create(&src, ctx, topic_1, handle_src_event, NULL, evq); +00111 err = lbm_src_create(&src, ctx, topic_1, handle_src_event, NULL, evq);@@ -40,7 +40,7 @@Processing Events on the Event Queue
will execute queued events on the thread that called lbm_event_dispatch. Events will be processed for the specified amount of time.-00114 if(lbm_event_dispatch(evq, 10000) == LBM_FAILURE) { +00116 err = lbm_event_dispatch(evq, 10000);@@ -51,9 +51,12 @@Cleanup
queue is empty and no new events are being generated, the event queue can safely be _deleted()'ed.-00122 lbm_src_delete(src); -00123 lbm_context_delete(ctx); -00124 lbm_event_queue_delete(evq); +00126 err = lbm_src_delete(src); +00127 EX_LBM_CHK(err); +00128 err = lbm_context_delete(ctx); +00129 EX_LBM_CHK(err); +00130 err = lbm_event_queue_delete(evq); +00131 EX_LBM_CHK(err);diff --git a/event_q_src/c/event_q_src_c.slsrc b/event_q_src/c/event_q_src_c.slsrc index 651078b..1161f3e 100644 --- a/event_q_src/c/event_q_src_c.slsrc +++ b/event_q_src/c/event_q_src_c.slsrc @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* event_q_src.c + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -15,6 +34,16 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Source event handler. the UM library passes all per-source events */ /* back to the application. This will by default execute on the context */ /* thread. Therefore there should be no blocking calls made. If you must */ @@ -39,17 +68,17 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) break; } return 0; -} +} /* handle_src_event */ + -main() +int main(int argc, char **argv) { 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 */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -62,76 +91,56 @@ main() } #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); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* Create an event queue and associate it with a callback */ /* =semlit,block,evq_create= */ - if (lbm_event_queue_create(&evq, NULL, NULL, NULL) == LBM_FAILURE) { + err = lbm_event_queue_create(&evq, NULL, NULL, NULL); /* =semlit,endblock,evq_create= */ - fprintf(stderr, "lbm_event_queue_create: %s\n", lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Creating the source */ /* =semlit,block,src_create= */ err = lbm_src_create(&src, ctx, topic_1, handle_src_event, NULL, evq); /* =semlit,endblock,src_create= */ - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* 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. */ /* =semlit,block,evq_run= */ - if(lbm_event_dispatch(evq, 10000) == LBM_FAILURE) { + err = lbm_event_dispatch(evq, 10000); /* =semlit,endblock,evq_run= */ + if (err == 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); + err = lbm_src_topic_attr_delete(tattr); + EX_LBM_CHK(err); /* Finished with all LBM functions, delete the source and context object. */ /* =semlit,block,evq_close= */ - lbm_src_delete(src); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); /* =semlit,endblock,evq_close= */ + #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/event_q_src/c/event_q_src_c.slsrc.html b/event_q_src/c/event_q_src_c.slsrc.html index b4ac65b..5e90ca0 100644 --- a/event_q_src/c/event_q_src_c.slsrc.html +++ b/event_q_src/c/event_q_src_c.slsrc.html @@ -114,38 +114,66 @@ 00096 00097 00098 -00099 +00099 00100 00101 00102 00103 00104 -00105 +00105 00106 -00107 +00107 00108 00109 00110 -00111 +00111 00112 00113 -00114 +00114 00115 -00116 +00116 00117 00118 00119 00120 00121 -00122 -00123 -00124 +00122 +00123 +00124 00125 -00126 -00127 -00128 -00129 - /* Example on setting Ultra Messaging attributes */ +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 + /* event_q_src.c + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -162,6 +190,16 @@ #include <lbm/lbm.h> + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + /* Source event handler. the UM library passes all per-source events */ /* back to the application. This will by default execute on the context */ /* thread. Therefore there should be no blocking calls made. If you must */ @@ -186,17 +224,17 @@ break; } return 0; - } + } /* handle_src_event */ + - main() + int main(int argc, char **argv) { 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 */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -209,71 +247,51 @@ } #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); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + err = lbm_event_queue_create(&evq, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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) { + err = lbm_event_dispatch(evq, 10000); + if (err == 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); + err = lbm_src_topic_attr_delete(tattr); + EX_LBM_CHK(err); /* Finished with all LBM functions, delete the source and context object. */ - lbm_src_delete(src); - lbm_context_delete(ctx); - lbm_event_queue_delete(evq); + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + err = lbm_event_queue_delete(evq); + EX_LBM_CHK(err); + #if defined(_MSC_VER) WSACleanup(); #endif - } + return 0; + } /* main */ diff --git a/handle_burst/c/handle_burst.c b/handle_burst/c/handle_burst.c index 38567d6..c14de67 100644 --- a/handle_burst/c/handle_burst.c +++ b/handle_burst/c/handle_burst.c @@ -1,4 +1,23 @@ -/* handle_burst.c - http://ultramessaging.github.io/UMExamples */ +/* handle_burst.c - see http://ultramessaging.github.io/UMExamples/handle_burst/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include#if defined(_MSC_VER) @@ -16,21 +35,21 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Used to track the last sequence number received */ int last_sqn = 0; + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: last_sqn = msg->sequence_number; @@ -51,15 +70,15 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } return 0; -} +} /* rcv_handle_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -78,7 +97,7 @@ main() /* Create receiver for receiving request and sending response */ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -95,4 +114,5 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif + return 0; } /* main */ diff --git a/handle_burst/c/handle_burst.sldoc.html b/handle_burst/c/handle_burst.sldoc.html index 95d18d3..9712872 100644 --- a/handle_burst/c/handle_burst.sldoc.html +++ b/handle_burst/c/handle_burst.sldoc.html @@ -44,15 +44,15 @@ Context and Receiver Creation
Standard context and receiver creation, with a minimal amount of options set:
-00076 err = lbm_context_create(&ctx, NULL, NULL, NULL); -00077 EX_LBM_CHK(err); -00078 -00079 /* Create receiver for receiving request and sending response */ -00080 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); -00081 EX_LBM_CHK(err); -00082 -00083 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); -00084 EX_LBM_CHK(err); +00095 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00096 EX_LBM_CHK(err); +00097 +00098 /* Create receiver for receiving request and sending response */ +00099 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); +00100 EX_LBM_CHK(err); +00101 +00102 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); +00103 EX_LBM_CHK(err);@@ -67,9 +67,9 @@Receiver Message Callback
be processed later on a spearate thread. In either case, the last sequence number should be updated here:-00035 case LBM_MSG_DATA: -00036 last_sqn = msg->sequence_number; -00037 break; +00054 case LBM_MSG_DATA: +00055 last_sqn = msg->sequence_number; +00056 break;@@ -77,9 +77,9 @@Receiver Message Callback
in this event is the message fragment that is unrecoverable, so it should set the last sequence number variable here as well:-00038 case LBM_MSG_UNRECOVERABLE_LOSS: -00039 last_sqn = msg->sequence_number; -00040 break; +00057 case LBM_MSG_UNRECOVERABLE_LOSS: +00058 last_sqn = msg->sequence_number; +00059 break;@@ -88,13 +88,13 @@Receiver Message Callback
could be another burst loss event, and the application will want to calculate the size of that burst as well:-00041 case LBM_MSG_UNRECOVERABLE_LOSS_BURST: -00042 { -00043 int burst = msg->sequence_number - last_sqn; -00044 printf("WARNING: Burst loss of %d messages!\n", burst); -00045 last_sqn = msg->sequence_number; -00046 break; -00047 } +00060 case LBM_MSG_UNRECOVERABLE_LOSS_BURST: +00061 { +00062 int burst = msg->sequence_number - last_sqn; +00063 printf("WARNING: Burst loss of %d messages!\n", burst); +00064 last_sqn = msg->sequence_number; +00065 break; +00066 }@@ -103,19 +103,19 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 #if defined(_MSC_VER) -00005 /* Windows-only includes */ -00006 #include <winsock2.h> -00007 #define SLEEP(s) Sleep((s)*1000) -00008 #else -00009 /* Unix-only includes */ -00010 #include <stdlib.h> -00011 #include <unistd.h> -00012 #define SLEEP(s) sleep(s) -00013 #endif -00014 -00015 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 #if defined(_MSC_VER) +00024 /* Windows-only includes */ +00025 #include <winsock2.h> +00026 #define SLEEP(s) Sleep((s)*1000) +00027 #else +00028 /* Unix-only includes */ +00029 #include <stdlib.h> +00030 #include <unistd.h> +00031 #define SLEEP(s) sleep(s) +00032 #endif +00033 +00034 #include <lbm/lbm.h>@@ -123,16 +123,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00064 #if defined(_WIN32) -00065 /* windows-specific code */ -00066 WSADATA wsadata; -00067 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00068 if (wsStat != 0) -00069 { -00070 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00071 exit(1); -00072 } -00073 #endif +00083 #if defined(_WIN32) +00084 /* windows-specific code */ +00085 WSADATA wsadata; +00086 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00087 if (wsStat != 0) +00088 { +00089 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00090 exit(1); +00091 } +00092 #endifdiff --git a/handle_burst/c/handle_burst_c.slsrc b/handle_burst/c/handle_burst_c.slsrc index a042f23..d72392d 100644 --- a/handle_burst/c/handle_burst_c.slsrc +++ b/handle_burst/c/handle_burst_c.slsrc @@ -1,4 +1,23 @@ -/* handle_burst.c - http://ultramessaging.github.io/UMExamples */ +/* handle_burst.c - see http://ultramessaging.github.io/UMExamples/handle_burst/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -18,23 +37,23 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Used to track the last sequence number received */ /* =semlit,block,last=*/ int last_sqn = 0; /* =semlit,endblock,last=*/ + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { /* =semlit,block,data=*/ case LBM_MSG_DATA: @@ -61,15 +80,15 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } return 0; -} +} /* rcv_handle_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + int err; /* =semlit,block,windows=*/ #if defined(_WIN32) @@ -91,7 +110,7 @@ main() /* Create receiver for receiving request and sending response */ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -109,4 +128,5 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif + return 0; } /* main */ diff --git a/handle_burst/c/handle_burst_c.slsrc.html b/handle_burst/c/handle_burst_c.slsrc.html index 650d746..438558d 100644 --- a/handle_burst/c/handle_burst_c.slsrc.html +++ b/handle_burst/c/handle_burst_c.slsrc.html @@ -18,103 +18,142 @@ diff --git a/index.html b/index.html index 8504a38..6257d38 100644 --- a/index.html +++ b/index.html @@ -1,10 +1,17 @@ - - -
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 00016 00017 00018 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 00048 00049 00050 00051 00052 00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 00074 00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 00093 00094 -00095 -00096 -00097 -00098 - /* handle_burst.c - http://ultramessaging.github.io/UMExamples */ +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 + /* handle_burst.c - see http://ultramessaging.github.io/UMExamples/handle_burst/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> #if defined(_MSC_VER) @@ -132,21 +171,21 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Used to track the last sequence number received */ int last_sqn = 0; + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: last_sqn = msg->sequence_number; @@ -167,15 +206,15 @@ } return 0; - } + } /* rcv_handle_msg */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -194,7 +233,7 @@ /* Create receiver for receiving request and sending response */ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -211,6 +250,7 @@ /* Windows-specific cleanup overhead */ WSACleanup(); #endif + return 0; } /* main */ UMExamples - Learning the Ultra Messaging API by example - +UMExamples - Learning the Ultra Messaging API by example + + - -Welcome to UMExamples
+ +++ diff --git a/infa_logo.png b/infa_logo.png new file mode 100644 index 0000000..e3d8b45 Binary files /dev/null and b/infa_logo.png differ diff --git a/java_index.html b/java_index.html index 904d3e8..8e0be37 100644 --- a/java_index.html +++ b/java_index.html @@ -1,9 +1,17 @@ - - -++
+Welcome to UMExamples +
+ +© Copyright Informatica LLC 2004-2020. +
Ultra Messaging Examples (UMExamples) is a documentation suite aimed at providing high quality educational samples for the Informatica Ultra Messaging @@ -20,7 +27,8 @@
Welcome to UMExamples
examples are not available in all laguages.If you would like to see only those examples available in a particular language, -you can visit: C examples Java examples C#/.NET examples
+you can visit: +The master list is always available at: All examples
@@ -28,6 +36,7 @@Welcome to UMExamples
Examples
+
- - + +mtools C Informatica "mtools" are a set of multicast test tools. Binaries and source code available for free. cancelling_timers C Java C#/.NET Example on how a context can schedule and safely cancel timer callbacks check_flight_size_ewouldblock C Java C#/.NET A send can fail with an EWOULDBLOCK error, which can have different root causes. One cause for a persisted source is exceeding flight size. This example shows how to determine if flight size is the cause of an EWOULDBLOCK error. @@ -48,7 +57,39 @@ clean_shutdown C Java C#/.NET Example on how to properly clean up a UM application Examples
sequential_mode C Java C#/.NET Example on how to run a LBM application in sequential mode with a separate context thread setting_attributes C Java C#/.NET Examples on setting UM attributes via the API + source_notify_callbacks C Java C#/.NET A sample application that demonstrates how to configure and code the source_notification_callback feature for receivers src_rsp C A sample application that demonstrates source-based request responses. + ump_receiver_callbacks C Java C#/.NET A sample application that handles all UMP receiver callbacks and logs important data ump_src_failover C Example UMP source application that demonstrates how a persisted source can failover to a backup store
+ +Notices
+This software and documentation are provided only under a separate license +agreement containing restrictions on use and disclosure. +No part of this document may be reproduced or transmitted in any form, +by any means (electronic, photocopying, recording or otherwise) +without prior consent of Informatica LLC. + +
A current list of Informatica trademarks is available on the web at +https://www.informatica.com/trademarks.html. + +
Portions of this software and/or documentation are subject to copyright +held by third parties. +Required third party notices are included with the product. + +
Informatica software is protected by patents as detailed at +https://www.informatica.com/legal/patents.html. + +
The information in this documentation is subject to change without notice. +If you find any problems in this documentation, please report them to us in +writing at Informatica LLC 2100 Seaport Blvd. Redwood City, CA 94063. + +
Informatica products are warranted according to the terms and conditions +of the agreements under which they are provided. +
INFORMATICA LLC PROVIDES THE INFORMATION IN THIS DOCUMENT "AS IS" WITHOUT +WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT ANY WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OR +CONDITION OF NON-INFRINGEMENT. +UMExamples - Java Language - +UMExamples - Java Language + + - + ++diff --git a/late_join/c/late_join.c b/late_join/c/late_join.c index 2986fe2..378cdf9 100644 --- a/late_join/c/late_join.c +++ b/late_join/c/late_join.c @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* late_join.c - see http://ultramessaging.github.io/UMExamples/late_join/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include++
+Welcome to UMExamples +
+ +© Copyright Informatica LLC 2004-2020. +
Java Examples
Examples written in Java.
@@ -40,5 +48,36 @@Examples
source_notify_callbacks C Java C#/.NET A sample application that demonstrates how to configure and code the source_notification_callback feature for receivers + + ump_receiver_callbacks C Java C#/.NET A sample application that handles all UMP receiver callbacks and logs important data
+ +Notices
+This software and documentation are provided only under a separate license +agreement containing restrictions on use and disclosure. +No part of this document may be reproduced or transmitted in any form, +by any means (electronic, photocopying, recording or otherwise) +without prior consent of Informatica LLC. + +
A current list of Informatica trademarks is available on the web at +https://www.informatica.com/trademarks.html. + +
Portions of this software and/or documentation are subject to copyright +held by third parties. +Required third party notices are included with the product. + +
Informatica software is protected by patents as detailed at +https://www.informatica.com/legal/patents.html. + +
The information in this documentation is subject to change without notice. +If you find any problems in this documentation, please report them to us in +writing at Informatica LLC 2100 Seaport Blvd. Redwood City, CA 94063. + +
Informatica products are warranted according to the terms and conditions +of the agreements under which they are provided. +
INFORMATICA LLC PROVIDES THE INFORMATION IN THIS DOCUMENT "AS IS" WITHOUT +WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT ANY WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OR +CONDITION OF NON-INFRINGEMENT. +@@ -15,6 +34,16 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Received message handler (passed into lbm_rcv_create()) */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { @@ -27,7 +56,7 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) else printf("Normal Message. SQN: %d\n", msg->sequence_number); - //some processing + /* some processing */ break; case LBM_MSG_BOS: printf("Beggining of transport.\n"); @@ -40,18 +69,18 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } return 0; -} +} /* rcv_handle_msg */ + -main() +int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_topic_t *topic_1; /* pointer to topic object */ - lbm_src_t *early_src; /* pointer to source object */ - lbm_rcv_t *late_rcv; /* pointer to receiver object */ - lbm_topic_t *rtopic; /* pointer to receiver topic object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ - int err; /* return status of lbm functions (true=error) */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_topic_t *topic_1; /* pointer to topic object */ + lbm_src_t *early_src; /* pointer to source object */ + lbm_rcv_t *late_rcv; /* pointer to receiver object */ + lbm_topic_t *rtopic; /* pointer to receiver topic object */ + lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -64,91 +93,58 @@ main() } #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); - } - + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* 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); - } - + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); + /* Setting the transport via the source topic string method */ - if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } - if (lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1") - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } - + err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1"); + EX_LBM_CHK(err); + /* Allocating the source topic */ err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic", tattr); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); - /* Creating the source */ + /* Creating the source */ err = lbm_src_create(&early_src, ctx, topic_1, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Wait for topic resolution to happen */ - Sleep(1); + SLEEP(1); - /* Send a message... we should expect no one to get it because we haven't created the receiver - yet. */ + /* Send a message... we should expect no one to get it because we haven't + * created the receiver yet. */ err = lbm_src_send(early_src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); - /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_rcv_create(&late_rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); SLEEP(100000); - /* Finished with all LBM functions, delete the receiver and context object. */ - /* Delete the source topic attribute objects */ - lbm_src_topic_attr_delete(tattr); + /* Finished with all LBM functions, delete the receiver and context object. + * Delete the source topic attribute objects. */ + err = lbm_src_topic_attr_delete(tattr); + EX_LBM_CHK(err); /* Finished with all LBM functions, delete the source and context object. */ - lbm_src_delete(early_src); - lbm_rcv_delete(late_rcv); - lbm_context_delete(ctx); + err = lbm_src_delete(early_src); + EX_LBM_CHK(err); + err = lbm_rcv_delete(late_rcv); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif -} - + return 0; +} /* main */ diff --git a/late_join/c/late_join.sldoc.html b/late_join/c/late_join.sldoc.html index 4c1d3ce..d538a34 100644 --- a/late_join/c/late_join.sldoc.html +++ b/late_join/c/late_join.sldoc.html @@ -20,11 +20,8 @@ Enabling Late Join
Sources by default have late join disabled. To enable late join the application must do two things. The first is to enable late-join. This can be done as follows:
-00090 if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0 ) -00091 { -00092 fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); -00093 exit(1); -00094 } +00105 err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); +00106 EX_LBM_CHK(err);@@ -33,11 +30,8 @@Enabling Late Join
means that at least 1 message will be in the buffer at all times. This can be done as follows:-00095 if (lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1") -00096 { -00097 fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); -00098 exit(1); -00099 } +00107 err = lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1"); +00108 EX_LBM_CHK(err);@@ -47,19 +41,15 @@Create a source, send message
that the receiver can miss the first few messages published. This is because it takes a non-zero amount of time to resolve the source and join the underlying transport.-00110 err = lbm_src_create(&early_src, ctx, topic_1, NULL, NULL, NULL); -00111 if (err) -00112 { -00113 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00114 exit(1); -00115 } -00116 -00117 /* Wait for topic resolution to happen */ -00118 Sleep(1); -00119 -00120 /* Send a message... we should expect no one to get it because we haven't created the receiver -00121 yet. */ -00122 err = lbm_src_send(early_src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); +00115 err = lbm_src_create(&early_src, ctx, topic_1, NULL, NULL, NULL); +00116 EX_LBM_CHK(err); +00117 +00118 /* Wait for topic resolution to happen */ +00119 SLEEP(1); +00120 +00121 /* Send a message... we should expect no one to get it because we haven't +00122 * created the receiver yet. */ +00123 err = lbm_src_send(early_src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK);@@ -68,7 +58,7 @@Creating the receiver and receiving late join
the default does not have to be changed. Therefore, the receiver is simply created:-00132 err = lbm_rcv_create(&late_rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); +00128 err = lbm_rcv_create(&late_rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL);@@ -79,16 +69,16 @@Creating the receiver and receiving late join
be retransmitted via OTR, which is a separate type of retransmission that will not be covered in this example.-00021 switch (msg->type) { -00022 case LBM_MSG_DATA: -00023 if (msg->flags & LBM_MSG_FLAG_RETRANSMIT) -00024 printf("Processing Late Join Message. SQN: %d\n", msg->sequence_number); -00025 else if (msg->flags & LBM_MSG_FLAG_OTR) -00026 printf("Processing OTR Message. SQN: %d\n", msg->sequence_number); -00027 else -00028 printf("Normal Message. SQN: %d\n", msg->sequence_number); -00029 -00030 //some processing +00050 switch (msg->type) { +00051 case LBM_MSG_DATA: +00052 if (msg->flags & LBM_MSG_FLAG_RETRANSMIT) +00053 printf("Processing Late Join Message. SQN: %d\n", msg->sequence_number); +00054 else if (msg->flags & LBM_MSG_FLAG_OTR) +00055 printf("Processing OTR Message. SQN: %d\n", msg->sequence_number); +00056 else +00057 printf("Normal Message. SQN: %d\n", msg->sequence_number); +00058 +00059 /* some processing */@@ -96,9 +86,12 @@Cleanup
Cleanup in this case is simple. Simple close or delete all source & receiver objects, and then close or delete the context.
-00146 lbm_src_delete(early_src); -00147 lbm_rcv_delete(late_rcv); -00148 lbm_context_delete(ctx); +00139 err = lbm_src_delete(early_src); +00140 EX_LBM_CHK(err); +00141 err = lbm_rcv_delete(late_rcv); +00142 EX_LBM_CHK(err); +00143 err = lbm_context_delete(ctx); +00144 EX_LBM_CHK(err);diff --git a/late_join/c/late_join_c.slsrc b/late_join/c/late_join_c.slsrc index f67d708..0cb0882 100644 --- a/late_join/c/late_join_c.slsrc +++ b/late_join/c/late_join_c.slsrc @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* late_join.c - see http://ultramessaging.github.io/UMExamples/late_join/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -15,10 +34,20 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Received message handler (passed into lbm_rcv_create()) */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - /* =semlit,block,callback= */ + /* =semlit,block,callback= */ switch (msg->type) { case LBM_MSG_DATA: if (msg->flags & LBM_MSG_FLAG_RETRANSMIT) @@ -28,7 +57,7 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) else printf("Normal Message. SQN: %d\n", msg->sequence_number); - //some processing + /* some processing */ /* =semlit,endblock,callback= */ break; case LBM_MSG_BOS: @@ -42,18 +71,18 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } return 0; -} +} /* rcv_handle_msg */ + -main() +int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_topic_t *topic_1; /* pointer to topic object */ - lbm_src_t *early_src; /* pointer to source object */ - lbm_rcv_t *late_rcv; /* pointer to receiver object */ - lbm_topic_t *rtopic; /* pointer to receiver topic object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ - int err; /* return status of lbm functions (true=error) */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_topic_t *topic_1; /* pointer to topic object */ + lbm_src_t *early_src; /* pointer to source object */ + lbm_rcv_t *late_rcv; /* pointer to receiver object */ + lbm_topic_t *rtopic; /* pointer to receiver topic object */ + lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -66,101 +95,68 @@ main() } #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); - } - + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* 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); - } - + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); + /* Setting the transport via the source topic string method */ /* =semlit,block,enable_lj= */ - if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); + EX_LBM_CHK(err); /* =semlit,endblock,enable_lj= */ /* =semlit,block,configure_lj= */ - if (lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1") - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1"); + EX_LBM_CHK(err); /* =semlit,endblock,configure_lj= */ - + /* Allocating the source topic */ err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic", tattr); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); - /* Creating the source */ - /* =semlit,block,source= */ + /* Creating the source */ + /* =semlit,block,source= */ err = lbm_src_create(&early_src, ctx, topic_1, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Wait for topic resolution to happen */ - Sleep(1); + SLEEP(1); - /* Send a message... we should expect no one to get it because we haven't created the receiver - yet. */ + /* Send a message... we should expect no one to get it because we haven't + * created the receiver yet. */ err = lbm_src_send(early_src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); /* =semlit,endblock,source= */ - /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* =semlit,block,receiver= */ err = lbm_rcv_create(&late_rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); /* =semlit,endblock,receiver= */ - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); SLEEP(100000); - /* Finished with all LBM functions, delete the receiver and context object. */ - /* Delete the source topic attribute objects */ - lbm_src_topic_attr_delete(tattr); + /* Finished with all LBM functions, delete the receiver and context object. + * Delete the source topic attribute objects. */ + err = lbm_src_topic_attr_delete(tattr); + EX_LBM_CHK(err); /* Finished with all LBM functions, delete the source and context object. */ /* =semlit,block,cleanup= */ - lbm_src_delete(early_src); - lbm_rcv_delete(late_rcv); - lbm_context_delete(ctx); + err = lbm_src_delete(early_src); + EX_LBM_CHK(err); + err = lbm_rcv_delete(late_rcv); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); /* =semlit,endblock,cleanup= */ #if defined(_MSC_VER) WSACleanup(); #endif -} - + return 0; +} /* main */ diff --git a/late_join/c/late_join_c.slsrc.html b/late_join/c/late_join_c.slsrc.html index e878172..e34edba 100644 --- a/late_join/c/late_join_c.slsrc.html +++ b/late_join/c/late_join_c.slsrc.html @@ -36,16 +36,16 @@ 00018 00019 00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 00031 00032 00033 @@ -65,16 +65,16 @@ 00047 00048 00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 00060 00061 00062 @@ -105,31 +105,31 @@ 00087 00088 00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 -00099 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 00100 00101 00102 00103 00104 -00105 -00106 -00107 -00108 +00105 +00106 +00107 +00108 00109 -00110 -00111 -00112 -00113 -00114 +00110 +00111 +00112 +00113 +00114 00115 00116 00117 @@ -138,39 +138,54 @@ 00120 00121 00122 -00123 +00123 00124 00125 00126 00127 -00128 +00128 00129 00130 00131 -00132 +00132 00133 00134 00135 00136 00137 00138 -00139 -00140 -00141 -00142 -00143 -00144 +00139 +00140 +00141 +00142 +00143 +00144 00145 -00146 -00147 -00148 +00146 +00147 +00148 00149 00150 -00151 -00152 -00153 -00154 - /* Example on setting Ultra Messaging attributes */ + /* late_join.c - see http://ultramessaging.github.io/UMExamples/late_join/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -187,6 +202,16 @@ #include <lbm/lbm.h> + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + /* Received message handler (passed into lbm_rcv_create()) */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { @@ -199,7 +224,7 @@ else printf("Normal Message. SQN: %d\n", msg->sequence_number); - //some processing + /* some processing */ break; case LBM_MSG_BOS: printf("Beggining of transport.\n"); @@ -212,18 +237,18 @@ break; } return 0; - } + } /* rcv_handle_msg */ + - main() + int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_topic_t *topic_1; /* pointer to topic object */ - lbm_src_t *early_src; /* pointer to source object */ - lbm_rcv_t *late_rcv; /* pointer to receiver object */ - lbm_topic_t *rtopic; /* pointer to receiver topic object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ - int err; /* return status of lbm functions (true=error) */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_topic_t *topic_1; /* pointer to topic object */ + lbm_src_t *early_src; /* pointer to source object */ + lbm_rcv_t *late_rcv; /* pointer to receiver object */ + lbm_topic_t *rtopic; /* pointer to receiver topic object */ + lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -236,94 +261,61 @@ } #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); - } - + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* 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); - } - + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); + /* Setting the transport via the source topic string method */ - if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } - if (lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1") - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); - exit(1); - } - + err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(tattr, "retransmit_retention_size_threshold", "1"); + EX_LBM_CHK(err); + /* Allocating the source topic */ err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic", tattr); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); - /* Creating the source */ + /* Creating the source */ err = lbm_src_create(&early_src, ctx, topic_1, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Wait for topic resolution to happen */ - Sleep(1); + SLEEP(1); - /* Send a message... we should expect no one to get it because we haven't created the receiver - yet. */ + /* Send a message... we should expect no one to get it because we haven't + * created the receiver yet. */ err = lbm_src_send(early_src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); - /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); err = lbm_rcv_create(&late_rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); SLEEP(100000); - /* Finished with all LBM functions, delete the receiver and context object. */ - /* Delete the source topic attribute objects */ - lbm_src_topic_attr_delete(tattr); + /* Finished with all LBM functions, delete the receiver and context object. + * Delete the source topic attribute objects. */ + err = lbm_src_topic_attr_delete(tattr); + EX_LBM_CHK(err); /* Finished with all LBM functions, delete the source and context object. */ - lbm_src_delete(early_src); - lbm_rcv_delete(late_rcv); - lbm_context_delete(ctx); + err = lbm_src_delete(early_src); + EX_LBM_CHK(err); + err = lbm_rcv_delete(late_rcv); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif - } - + return 0; + } /* main */ diff --git a/load_config/c/load_config.c b/load_config/c/load_config.c index 04da4fe..07456c3 100644 --- a/load_config/c/load_config.c +++ b/load_config/c/load_config.c @@ -1,4 +1,23 @@ -/* load_config.c - http://ultramessaging.github.io/UMExamples */ +/* load_config.c - see http://ultramessaging.github.io/UMExamples/load_config/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -26,13 +45,16 @@ #define LBM_CONFIG_XML_FILE "../xml_config.xml" #define LBM_APPLICATION_NAME "processA" -main() + +int main(int argc, char **argv) { - int err; /* Used for checking API return codes */ + int err; err = lbm_config((const char *)LBM_CONFIG_FLAT_FILE); EX_LBM_CHK(err); err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); EX_LBM_CHK(err); -} + + return 0; +} /* main */ diff --git a/load_config/c/load_config.sldoc.html b/load_config/c/load_config.sldoc.html index 9f19e6b..8bd5996 100644 --- a/load_config/c/load_config.sldoc.html +++ b/load_config/c/load_config.sldoc.html @@ -53,9 +53,9 @@ Define Configuration File Names
of this sample application, they are simply defined as macros-00025 #define LBM_CONFIG_FLAT_FILE "../flat_config.cfg" -00026 #define LBM_CONFIG_XML_FILE "../xml_config.xml" -00027 #define LBM_APPLICATION_NAME "processA" +00044 #define LBM_CONFIG_FLAT_FILE "../flat_config.cfg" +00045 #define LBM_CONFIG_XML_FILE "../xml_config.xml" +00046 #define LBM_APPLICATION_NAME "processA"@@ -64,8 +64,8 @@Load Flat File
Here the application is using lbm_config() to load the flat file "flat_config.cfg":
-00033 err = lbm_config((const char *)LBM_CONFIG_FLAT_FILE); -00034 EX_LBM_CHK(err); +00053 err = lbm_config((const char *)LBM_CONFIG_FLAT_FILE); +00054 EX_LBM_CHK(err);@@ -79,8 +79,8 @@Load XML File
to specific attributes this application should be setting:-00036 err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); -00037 EX_LBM_CHK(err); +00056 err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); +00057 EX_LBM_CHK(err);@@ -90,14 +90,14 @@Error Checking
print a message and exit the program:-00016 /* Example error checking macro. Include after each UM call. */ -00017 #define EX_LBM_CHK(err) do { \ -00018 if ((err) < 0) { \ -00019 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ -00020 __FILE__, __LINE__, lbm_errmsg()); \ -00021 exit(1); \ -00022 } \ -00023 } while (0) +00035 /* Example error checking macro. Include after each UM call. */ +00036 #define EX_LBM_CHK(err) do { \ +00037 if ((err) < 0) { \ +00038 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ +00039 __FILE__, __LINE__, lbm_errmsg()); \ +00040 exit(1); \ +00041 } \ +00042 } while (0)@@ -113,18 +113,18 @@Includes
A small effort was made to provide a some portability between Unix and Windows. For example:
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #else -00009 /* Unix-only includes */ -00010 #include <stdlib.h> -00011 #include <unistd.h> -00012 #endif -00013 -00014 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #else +00028 /* Unix-only includes */ +00029 #include <stdlib.h> +00030 #include <unistd.h> +00031 #endif +00032 +00033 #include <lbm/lbm.h>diff --git a/load_config/c/load_config_c.slsrc b/load_config/c/load_config_c.slsrc index d010a11..b0ed194 100644 --- a/load_config/c/load_config_c.slsrc +++ b/load_config/c/load_config_c.slsrc @@ -1,4 +1,23 @@ -/* load_config.c - http://ultramessaging.github.io/UMExamples */ +/* load_config.c - see http://ultramessaging.github.io/UMExamples/load_config/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -32,10 +51,11 @@ #define LBM_APPLICATION_NAME "processA" /* =semlit,endblock,define_configs=*/ -main() + +int main(int argc, char **argv) { /* =semlit,block,vars=*/ - int err; /* Used for checking API return codes */ + int err; /* =semlit,endblock,vars=*/ /* =semlit,block,flat_file=*/ @@ -47,4 +67,6 @@ main() err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); EX_LBM_CHK(err); /* =semlit,endblock,xml_file=*/ -} + + return 0; +} /* main */ diff --git a/load_config/c/load_config_c.slsrc.html b/load_config/c/load_config_c.slsrc.html index f99bad7..49bc5d6 100644 --- a/load_config/c/load_config_c.slsrc.html +++ b/load_config/c/load_config_c.slsrc.html @@ -18,43 +18,84 @@ diff --git a/logging_callback/c/logging_callback.c b/logging_callback/c/logging_callback.c index 595cadf..54b52dd 100644 --- a/logging_callback/c/logging_callback.c +++ b/logging_callback/c/logging_callback.c @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* logging_callback.c - see http://ultramessaging.github.io/UMExamples/logging_callback/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 00015 -00016 -00017 -00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 - /* load_config.c - http://ultramessaging.github.io/UMExamples */ +00016 +00017 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 + /* load_config.c - see http://ultramessaging.github.io/UMExamples/load_config/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -82,16 +123,19 @@ #define LBM_CONFIG_XML_FILE "../xml_config.xml" #define LBM_APPLICATION_NAME "processA" - main() + + int main(int argc, char **argv) { - int err; /* Used for checking API return codes */ + int err; err = lbm_config((const char *)LBM_CONFIG_FLAT_FILE); EX_LBM_CHK(err); err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); EX_LBM_CHK(err); - } + + return 0; + } /* main */ @@ -15,81 +34,74 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* Logging callback */ int lbm_log_msg(int level, const char *message, void *clientd) { - printf("LOG Level %d: %s\n", level, message); - return 0; -} + printf("LOG Level %d: %s\n", level, message); + return 0; +} /* lbm_log_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - lbm_topic_t *topic; /* pointer to topic object */ - lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ - lbm_src_t *src; /* pointer to source object */ - int err; /* return status of lbm functions (true=error) */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_topic_t *topic; /* pointer to topic object */ + lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ + lbm_src_t *src; /* pointer to source object */ + int err; #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); - } + /* 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 - /* Setup logging callback */ - if (lbm_log(lbm_log_msg, NULL) == LBM_FAILURE) { - fprintf(stderr, "lbm_log: %s\n", lbm_errmsg()); - exit(1); - } + /* Setup logging callback */ + err = lbm_log(lbm_log_msg, NULL); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); /* Setting late_join */ - if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0) - { - fprintf(stderr, "lbm_context_attr_str_setopt:late_join: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); + EX_LBM_CHK(err); /* Allocating the topic */ err = lbm_src_topic_alloc(&topic, ctx, "test.topic.1", tattr); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Creating the source */ err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* At the very least, the following core message should print via the logging callback: */ /* LOG Level 5: Core-5688-539: NOTICE: Source "test.topic.1" has no retention settings (1 message retained max) */ /* Cleanup */ - lbm_src_delete(src); - lbm_context_delete(ctx); -} + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + return 0; +} /* main */ diff --git a/logging_callback/c/logging_callback.sldoc.html b/logging_callback/c/logging_callback.sldoc.html index fc92d20..8bf8309 100644 --- a/logging_callback/c/logging_callback.sldoc.html +++ b/logging_callback/c/logging_callback.sldoc.html @@ -50,10 +50,8 @@ Setting the Logging Callback
itself. It can be used like this:-00046 if (lbm_log(lbm_log_msg, NULL) == LBM_FAILURE) { -00047 fprintf(stderr, "lbm_log: %s\n", lbm_errmsg()); -00048 exit(1); -00049 } +00075 err = lbm_log(lbm_log_msg, NULL); +00076 EX_LBM_CHK(err);@@ -63,11 +61,12 @@Defining the Logging Callback
log file:-00019 int lbm_log_msg(int level, const char *message, void *clientd) -00020 { -00021 printf("LOG Level %d: %s\n", level, message); -00022 return 0; -00023 } +00047 /* Logging callback */ +00048 int lbm_log_msg(int level, const char *message, void *clientd) +00049 { +00050 printf("LOG Level %d: %s\n", level, message); +00051 return 0; +00052 } /* lbm_log_msg */@@ -87,11 +86,8 @@Triggering a log message
Setting the attribute looks like this:
-00066 if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0) -00067 { -00068 fprintf(stderr, "lbm_context_attr_str_setopt:late_join: %s\n", lbm_errmsg()); -00069 exit(1); -00070 } +00086 err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); +00087 EX_LBM_CHK(err);@@ -100,20 +96,20 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>@@ -121,16 +117,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00034 #if defined(_MSC_VER) -00035 /* windows-specific code */ -00036 WSADATA wsadata; -00037 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00038 if (wsStat != 0) -00039 { -00040 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00041 exit(1); -00042 } -00043 #endif +00063 #if defined(_MSC_VER) +00064 /* windows-specific code */ +00065 WSADATA wsadata; +00066 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00067 if (wsStat != 0) +00068 { +00069 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00070 exit(1); +00071 } +00072 #endifdiff --git a/logging_callback/c/logging_callback_c.slsrc b/logging_callback/c/logging_callback_c.slsrc index bc9d38f..445dcc2 100644 --- a/logging_callback/c/logging_callback_c.slsrc +++ b/logging_callback/c/logging_callback_c.slsrc @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* logging_callback.c - see http://ultramessaging.github.io/UMExamples/logging_callback/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -17,91 +36,84 @@ #include /* =semlit,endblock,includes=*/ -/* Logging callback */ +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + /* =semlit,block,logging_cb=*/ +/* Logging callback */ int lbm_log_msg(int level, const char *message, void *clientd) { - printf("LOG Level %d: %s\n", level, message); - return 0; -} + printf("LOG Level %d: %s\n", level, message); + return 0; +} /* lbm_log_msg */ /* =semlit,endblock,logging_cb=*/ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - lbm_topic_t *topic; /* pointer to topic object */ - lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ - lbm_src_t *src; /* pointer to source object */ - int err; /* return status of lbm functions (true=error) */ - - /* =semlit,block,windows=*/ + lbm_context_t *ctx; /* pointer to context object */ + lbm_topic_t *topic; /* pointer to topic object */ + lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ + lbm_src_t *src; /* pointer to source object */ + int err; + + /* =semlit,block,windows=*/ #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); - } + /* 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 - /* =semlit,endblock,windows=*/ + /* =semlit,endblock,windows=*/ - /* Setup logging callback */ + /* Setup logging callback */ /* =semlit,block,set_cb=*/ - if (lbm_log(lbm_log_msg, NULL) == LBM_FAILURE) { - fprintf(stderr, "lbm_log: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_log(lbm_log_msg, NULL); + EX_LBM_CHK(err); /* =semlit,endblock,set_cb=*/ - /* =semlit,block,create= */ - err = lbm_context_create(&ctx, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - /* =semlit,endblock,create=*/ + /* =semlit,block,create= */ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,create=*/ /* 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); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); /* Setting late_join */ /* =semlit,block,late_join=*/ - if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0) - { - fprintf(stderr, "lbm_context_attr_str_setopt:late_join: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); + EX_LBM_CHK(err); /* =semlit,endblock,late_join=*/ /* Allocating the topic */ err = lbm_src_topic_alloc(&topic, ctx, "test.topic.1", tattr); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Creating the source */ err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* At the very least, the following core message should print via the logging callback: */ /* LOG Level 5: Core-5688-539: NOTICE: Source "test.topic.1" has no retention settings (1 message retained max) */ /* Cleanup */ - lbm_src_delete(src); - lbm_context_delete(ctx); -} + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + return 0; +} /* main */ diff --git a/logging_callback/c/logging_callback_c.slsrc.html b/logging_callback/c/logging_callback_c.slsrc.html index 9e61975..42dedf5 100644 --- a/logging_callback/c/logging_callback_c.slsrc.html +++ b/logging_callback/c/logging_callback_c.slsrc.html @@ -18,91 +18,91 @@ diff --git a/minsrc/c/minsrc.c b/minsrc/c/minsrc.c index b0f7a26..659bca4 100644 --- a/minsrc/c/minsrc.c +++ b/minsrc/c/minsrc.c @@ -1,4 +1,23 @@ -/* minsrc.c, see http://ultramessaging.github.io/UMExamples/minsrc/c/ */ +/* minsrc.c - see http://ultramessaging.github.io/UMExamples/minsrc/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 00044 00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 00057 00058 00059 00060 00061 00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 00073 00074 -00075 -00076 +00075 +00076 00077 -00078 -00079 +00078 +00079 00080 00081 00082 00083 00084 00085 -00086 -00087 +00086 +00087 00088 00089 00090 @@ -111,7 +111,38 @@ 00093 00094 00095 - /* Code Disclaimer? */ +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 + /* logging_callback.c - see http://ultramessaging.github.io/UMExamples/logging_callback/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -128,84 +159,77 @@ #include <lbm/lbm.h> - /* Logging callback */ - int lbm_log_msg(int level, const char *message, void *clientd) + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + + /* Logging callback */ + int lbm_log_msg(int level, const char *message, void *clientd) { - printf("LOG Level %d: %s\n", level, message); - return 0; - } + printf("LOG Level %d: %s\n", level, message); + return 0; + } /* lbm_log_msg */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* pointer to context object */ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - lbm_topic_t *topic; /* pointer to topic object */ - lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ - lbm_src_t *src; /* pointer to source object */ - int err; /* return status of lbm functions (true=error) */ + lbm_context_t *ctx; /* pointer to context object */ + lbm_topic_t *topic; /* pointer to topic object */ + lbm_src_topic_attr_t *tattr; /* pointer to source attribute object */ + lbm_src_t *src; /* pointer to source object */ + int err; #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); - } + /* 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 - /* Setup logging callback */ - if (lbm_log(lbm_log_msg, NULL) == LBM_FAILURE) { - fprintf(stderr, "lbm_log: %s\n", lbm_errmsg()); - exit(1); - } + /* Setup logging callback */ + err = lbm_log(lbm_log_msg, NULL); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); /* Setting late_join */ - if (lbm_src_topic_attr_str_setopt(tattr, "late_join", "1") != 0) - { - fprintf(stderr, "lbm_context_attr_str_setopt:late_join: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "late_join", "1"); + EX_LBM_CHK(err); /* Allocating the topic */ err = lbm_src_topic_alloc(&topic, ctx, "test.topic.1", tattr); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Creating the source */ err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* At the very least, the following core message should print via the logging callback: */ /* LOG Level 5: Core-5688-539: NOTICE: Source "test.topic.1" has no retention settings (1 message retained max) */ /* Cleanup */ - lbm_src_delete(src); - lbm_context_delete(ctx); - } + err = lbm_src_delete(src); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + return 0; + } /* main */ @@ -17,70 +36,71 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object: container for UM "instance". */ - lbm_src_t *src; /* Source object: for sending messages. */ - int err; /* UM functions normally return 0 (success) or -1 (error). */ + lbm_context_t *ctx; /* Context object: container for UM "instance". */ + lbm_src_t *src; /* Source object: for sending messages. */ + int err; #if defined(_MSC_VER) - /* Windows-specific startup overhead */ - WSADATA wsadata; - int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); - if (wsa_err != 0) { - printf("line %d: wsStat=%d\n",__LINE__,wsStat); - fprintf(stderr, "%s:%d, WSAStartup error: %d\n", - __FILE__, __LINE__, wsa_err); - exit(1); - } + /* Windows-specific startup overhead */ + WSADATA wsadata; + int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); + if (wsa_err != 0) { + printf("line %d: wsStat=%d\n",__LINE__,wsStat); + fprintf(stderr, "%s:%d, WSAStartup error: %d\n", + __FILE__, __LINE__, wsa_err); + exit(1); + } #endif + /*** Initialization: create necessary UM objects. ***/ - /*** Initialization: create necessary UM objects. ***/ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, NULL, NULL, NULL); - EX_LBM_CHK(err); + { + lbm_topic_t *topic; /* Topic object: only needed temporarily. */ - { - lbm_topic_t *topic; /* Topic object: only needed temporarily. */ + err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); - EX_LBM_CHK(err); + err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + } - err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - EX_LBM_CHK(err); - } + SLEEP(1); /* Let topic resolution execute. */ - SLEEP(1); /* Let topic resolution execute. */ + /*** Send a message. ***/ - /*** Send a message. ***/ + err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); + EX_LBM_CHK(err); - err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); - EX_LBM_CHK(err); + /*** Cleanup: delete UM objects. ***/ - /*** Cleanup: delete UM objects. ***/ + SLEEP(3); /* Linger a bit to allow retransmissions. */ - SLEEP(3); /* Linger a bit to allow retransmissions. */ + err = lbm_src_delete(src); + EX_LBM_CHK(err); - err = lbm_src_delete(src); - EX_LBM_CHK(err); - - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif + + return 0; } /* main */ diff --git a/minsrc/c/minsrc.sldoc.html b/minsrc/c/minsrc.sldoc.html index 0ab5d4c..a91bc73 100644 --- a/minsrc/c/minsrc.sldoc.html +++ b/minsrc/c/minsrc.sldoc.html @@ -31,10 +31,10 @@ Initialization
created. The first object to be created is a UM context object:-00047 /*** Initialization: create necessary UM objects. ***/ -00048 -00049 err = lbm_context_create(&ctx, NULL, NULL, NULL); -00050 EX_LBM_CHK(err); +00065 /*** Initialization: create necessary UM objects. ***/ +00066 +00067 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00068 EX_LBM_CHK(err);@@ -55,15 +55,15 @@Initialization
the object used subsequently to send messages.-00052 { -00053 lbm_topic_t *topic; /* Topic object: only needed temporarily. */ -00054 -00055 err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); -00056 EX_LBM_CHK(err); -00057 -00058 err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); -00059 EX_LBM_CHK(err); -00060 } +00070 { +00071 lbm_topic_t *topic; /* Topic object: only needed temporarily. */ +00072 +00073 err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); +00074 EX_LBM_CHK(err); +00075 +00076 err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); +00077 EX_LBM_CHK(err); +00078 }@@ -88,7 +88,7 @@Initialization
applications to discover this new source:-00062 SLEEP(1); /* Let topic resolution execute. */ +00080 SLEEP(1); /* Let topic resolution execute. */@@ -113,10 +113,10 @@Publishing
Now that initialization is complete, it is time to send a message:
-00065 /*** Send a message. ***/ -00066 -00067 err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); -00068 EX_LBM_CHK(err); +00083 /*** Send a message. ***/ +00084 +00085 err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); +00086 EX_LBM_CHK(err);@@ -153,9 +153,9 @@Cleanup
completed since the last send, so a short sleep is included:-00071 /*** Cleanup: delete UM objects. ***/ -00072 -00073 SLEEP(3); /* Linger a bit to allow retransmissions. */ +00089 /*** Cleanup: delete UM objects. ***/ +00090 +00091 SLEEP(3); /* Linger a bit to allow retransmissions. */@@ -176,11 +176,11 @@Cleanup
When deleting UM objects, order of deletion is important:
-00075 err = lbm_src_delete(src); -00076 EX_LBM_CHK(err); -00077 -00078 err = lbm_context_delete(ctx); -00079 EX_LBM_CHK(err); +00093 err = lbm_src_delete(src); +00094 EX_LBM_CHK(err); +00095 +00096 err = lbm_context_delete(ctx); +00097 EX_LBM_CHK(err);@@ -197,16 +197,16 @@Misc
between Unix and Windows. For example:-00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif@@ -225,14 +225,14 @@Misc
taken: if anything unexpected happens, print a message and exit the program:-00018 /* Example error checking macro. Include after each UM call. */ -00019 #define EX_LBM_CHK(err) do { \ -00020 if ((err) < 0) { \ -00021 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ -00022 __FILE__, __LINE__, lbm_errmsg()); \ -00023 exit(1); \ -00024 } \ -00025 } while (0) +00037 /* Example error checking macro. Include after each UM call. */ +00038 #define EX_LBM_CHK(err) do { \ +00039 if ((err) < 0) { \ +00040 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ +00041 __FILE__, __LINE__, lbm_errmsg()); \ +00042 exit(1); \ +00043 } \ +00044 } while (0)@@ -258,23 +258,23 @@Misc
must at some point call WSAStartup():-00028 int main(int argc, char **argv) -00029 { -00030 lbm_context_t *ctx; /* Context object: container for UM "instance". */ -00031 lbm_src_t *src; /* Source object: for sending messages. */ -00032 int err; /* UM functions normally return 0 (success) or -1 (error). */ -00033 -00034 #if defined(_MSC_VER) -00035 /* Windows-specific startup overhead */ -00036 WSADATA wsadata; -00037 int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); -00038 if (wsa_err != 0) { -00039 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00040 fprintf(stderr, "%s:%d, WSAStartup error: %d\n", -00041 __FILE__, __LINE__, wsa_err); -00042 exit(1); -00043 } -00044 #endif +00047 int main(int argc, char **argv) +00048 { +00049 lbm_context_t *ctx; /* Context object: container for UM "instance". */ +00050 lbm_src_t *src; /* Source object: for sending messages. */ +00051 int err; +00052 +00053 #if defined(_MSC_VER) +00054 /* Windows-specific startup overhead */ +00055 WSADATA wsadata; +00056 int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); +00057 if (wsa_err != 0) { +00058 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00059 fprintf(stderr, "%s:%d, WSAStartup error: %d\n", +00060 __FILE__, __LINE__, wsa_err); +00061 exit(1); +00062 } +00063 #endif@@ -283,10 +283,10 @@Misc
after before exit:-00082 #if defined(_MSC_VER) -00083 /* Windows-specific cleanup overhead */ -00084 WSACleanup(); -00085 #endif +00100 #if defined(_MSC_VER) +00101 /* Windows-specific cleanup overhead */ +00102 WSACleanup(); +00103 #endifdiff --git a/minsrc/c/minsrc_c.slsrc b/minsrc/c/minsrc_c.slsrc index feaab60..915371f 100644 --- a/minsrc/c/minsrc_c.slsrc +++ b/minsrc/c/minsrc_c.slsrc @@ -1,4 +1,23 @@ -/* minsrc.c, see http://ultramessaging.github.io/UMExamples/minsrc/c/ */ +/* minsrc.c - see http://ultramessaging.github.io/UMExamples/minsrc/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -20,11 +39,11 @@ /*=semlit,block,ex_lbm_chk=*/ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /*=semlit,endblock,ex_lbm_chk=*/ @@ -32,75 +51,76 @@ /*=semlit,block,wsa_start=*/ int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object: container for UM "instance". */ - lbm_src_t *src; /* Source object: for sending messages. */ - int err; /* UM functions normally return 0 (success) or -1 (error). */ + lbm_context_t *ctx; /* Context object: container for UM "instance". */ + lbm_src_t *src; /* Source object: for sending messages. */ + int err; #if defined(_MSC_VER) - /* Windows-specific startup overhead */ - WSADATA wsadata; - int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); - if (wsa_err != 0) { - printf("line %d: wsStat=%d\n",__LINE__,wsStat); - fprintf(stderr, "%s:%d, WSAStartup error: %d\n", - __FILE__, __LINE__, wsa_err); - exit(1); - } + /* Windows-specific startup overhead */ + WSADATA wsadata; + int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); + if (wsa_err != 0) { + printf("line %d: wsStat=%d\n",__LINE__,wsStat); + fprintf(stderr, "%s:%d, WSAStartup error: %d\n", + __FILE__, __LINE__, wsa_err); + exit(1); + } #endif /*=semlit,endblock,wsa_start=*/ + /*=semlit,block,ctx_create=*/ + /*** Initialization: create necessary UM objects. ***/ -/*=semlit,block,ctx_create=*/ - /*** Initialization: create necessary UM objects. ***/ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /*=semlit,endblock,ctx_create=*/ - err = lbm_context_create(&ctx, NULL, NULL, NULL); - EX_LBM_CHK(err); -/*=semlit,endblock,ctx_create=*/ + /*=semlit,block,src_create=*/ + { + lbm_topic_t *topic; /* Topic object: only needed temporarily. */ -/*=semlit,block,src_create=*/ - { - lbm_topic_t *topic; /* Topic object: only needed temporarily. */ + err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); - EX_LBM_CHK(err); + err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + } + /*=semlit,endblock,src_create=*/ - err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - EX_LBM_CHK(err); - } -/*=semlit,endblock,src_create=*/ + /*=semlit,block,tr_sleep=*/ + SLEEP(1); /* Let topic resolution execute. */ + /*=semlit,endblock,tr_sleep=*/ -/*=semlit,block,tr_sleep=*/ - SLEEP(1); /* Let topic resolution execute. */ -/*=semlit,endblock,tr_sleep=*/ + /*=semlit,block,sending=*/ + /*** Send a message. ***/ -/*=semlit,block,sending=*/ - /*** Send a message. ***/ + err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); + EX_LBM_CHK(err); + /*=semlit,endblock,sending=*/ - err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); - EX_LBM_CHK(err); -/*=semlit,endblock,sending=*/ + /*=semlit,block,linger=*/ + /*** Cleanup: delete UM objects. ***/ -/*=semlit,block,linger=*/ - /*** Cleanup: delete UM objects. ***/ + SLEEP(3); /* Linger a bit to allow retransmissions. */ + /*=semlit,endblock,linger=*/ - SLEEP(3); /* Linger a bit to allow retransmissions. */ -/*=semlit,endblock,linger=*/ + /*=semlit,block,delobj=*/ + err = lbm_src_delete(src); + EX_LBM_CHK(err); -/*=semlit,block,delobj=*/ - err = lbm_src_delete(src); - EX_LBM_CHK(err); - - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); -/*=semlit,endblock,delobj=*/ + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + /*=semlit,endblock,delobj=*/ /*=semlit,block,wsa_clean=*/ #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif /*=semlit,endblock,wsa_clean=*/ + + return 0; } /* main */ diff --git a/minsrc/c/minsrc_c.slsrc.html b/minsrc/c/minsrc_c.slsrc.html index 27e98f7..ae3303b 100644 --- a/minsrc/c/minsrc_c.slsrc.html +++ b/minsrc/c/minsrc_c.slsrc.html @@ -20,89 +20,128 @@ 00002 00003 00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 00015 00016 00017 -00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 00045 00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 00064 -00065 -00066 -00067 -00068 +00065 +00066 +00067 +00068 00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 -00080 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 00081 -00082 -00083 -00084 -00085 -00086 - /* minsrc.c, see http://ultramessaging.github.io/UMExamples/minsrc/c/ */ +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 + /* minsrc.c - see http://ultramessaging.github.io/UMExamples/minsrc/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -121,72 +160,73 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object: container for UM "instance". */ - lbm_src_t *src; /* Source object: for sending messages. */ - int err; /* UM functions normally return 0 (success) or -1 (error). */ + lbm_context_t *ctx; /* Context object: container for UM "instance". */ + lbm_src_t *src; /* Source object: for sending messages. */ + int err; #if defined(_MSC_VER) - /* Windows-specific startup overhead */ - WSADATA wsadata; - int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); - if (wsa_err != 0) { - printf("line %d: wsStat=%d\n",__LINE__,wsStat); - fprintf(stderr, "%s:%d, WSAStartup error: %d\n", - __FILE__, __LINE__, wsa_err); - exit(1); - } + /* Windows-specific startup overhead */ + WSADATA wsadata; + int wsa_err = WSAStartup(MAKEWORD(2,2), &wsadata); + if (wsa_err != 0) { + printf("line %d: wsStat=%d\n",__LINE__,wsStat); + fprintf(stderr, "%s:%d, WSAStartup error: %d\n", + __FILE__, __LINE__, wsa_err); + exit(1); + } #endif + /*** Initialization: create necessary UM objects. ***/ - /*** Initialization: create necessary UM objects. ***/ - - err = lbm_context_create(&ctx, NULL, NULL, NULL); - EX_LBM_CHK(err); + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - { - lbm_topic_t *topic; /* Topic object: only needed temporarily. */ + { + lbm_topic_t *topic; /* Topic object: only needed temporarily. */ - err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); - EX_LBM_CHK(err); + err = lbm_src_topic_alloc(&topic, ctx, "Greeting", NULL); + EX_LBM_CHK(err); - err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); - EX_LBM_CHK(err); - } + err = lbm_src_create(&src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + } - SLEEP(1); /* Let topic resolution execute. */ + SLEEP(1); /* Let topic resolution execute. */ - /*** Send a message. ***/ + /*** Send a message. ***/ - err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); - EX_LBM_CHK(err); + err = lbm_src_send(src, "Hello!", 6, LBM_MSG_FLUSH | LBM_SRC_BLOCK); + EX_LBM_CHK(err); - /*** Cleanup: delete UM objects. ***/ + /*** Cleanup: delete UM objects. ***/ - SLEEP(3); /* Linger a bit to allow retransmissions. */ + SLEEP(3); /* Linger a bit to allow retransmissions. */ - err = lbm_src_delete(src); - EX_LBM_CHK(err); + err = lbm_src_delete(src); + EX_LBM_CHK(err); - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif + + return 0; } /* main */ diff --git a/multi_context/c/multi_context.c b/multi_context/c/multi_context.c index d17c5a3..5b5f9d1 100644 --- a/multi_context/c/multi_context.c +++ b/multi_context/c/multi_context.c @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* multi_context.c - see http://ultramessaging.github.io/UMExamples/multi_context/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -17,37 +36,38 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) #define LBM_CONFIG_XML_FILE "multi_context_config.xml" #define LBM_APPLICATION_NAME "main" -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx_1; /* Context object */ - lbm_context_attr_t * cattr_1; /* pointer to context attribute object */ - lbm_context_t *ctx_2; /* Context object */ - lbm_context_attr_t * cattr_2; /* pointer to context attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx_1; /* Context object */ + lbm_context_attr_t * cattr_1; /* pointer to context attribute object */ + lbm_context_t *ctx_2; /* Context object */ + lbm_context_attr_t * cattr_2; /* pointer to context attribute object */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_context_attr_create_from_xml(&cattr_1, "TRD1"); EX_LBM_CHK(err); @@ -69,4 +89,5 @@ main() #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/multi_context/c/multi_context.sldoc.html b/multi_context/c/multi_context.sldoc.html index 77c9a66..5e9179b 100644 --- a/multi_context/c/multi_context.sldoc.html +++ b/multi_context/c/multi_context.sldoc.html @@ -37,8 +37,8 @@ Define Configuration File Name
of this sample application, they are simply defined as macros-00027 #define LBM_CONFIG_XML_FILE "multi_context_config.xml" -00028 #define LBM_APPLICATION_NAME "main" +00046 #define LBM_CONFIG_XML_FILE "multi_context_config.xml" +00047 #define LBM_APPLICATION_NAME "main"@@ -48,8 +48,8 @@Load XML File
provided here in order to ensure that this application loads the correct configurations.-00049 err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); -00050 EX_LBM_CHK(err); +00069 err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); +00070 EX_LBM_CHK(err);@@ -58,11 +58,11 @@Creating Context 1
to a specific context name (TRD1) define in the XML using the appropriate API like so:-00052 err = lbm_context_attr_create_from_xml(&cattr_1, "TRD1"); -00053 EX_LBM_CHK(err); -00054 -00055 err = lbm_context_create(&ctx_1, cattr_1, NULL, NULL); -00056 EX_LBM_CHK(err); +00072 err = lbm_context_attr_create_from_xml(&cattr_1, "TRD1"); +00073 EX_LBM_CHK(err); +00074 +00075 err = lbm_context_create(&ctx_1, cattr_1, NULL, NULL); +00076 EX_LBM_CHK(err);@@ -70,11 +70,11 @@Creating Context 1
context attribute object:-00058 err = lbm_context_attr_create_from_xml(&cattr_2, "TRD2"); -00059 EX_LBM_CHK(err); -00060 -00061 err = lbm_context_create(&ctx_2, cattr_2, NULL, NULL); -00062 EX_LBM_CHK(err); +00078 err = lbm_context_attr_create_from_xml(&cattr_2, "TRD2"); +00079 EX_LBM_CHK(err); +00080 +00081 err = lbm_context_create(&ctx_2, cattr_2, NULL, NULL); +00082 EX_LBM_CHK(err);@@ -84,14 +84,14 @@Error Checking
print a message and exit the program:-00018 /* Example error checking macro. Include after each UM call. */ -00019 #define EX_LBM_CHK(err) do { \ -00020 if ((err) < 0) { \ -00021 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ -00022 __FILE__, __LINE__, lbm_errmsg()); \ -00023 exit(1); \ -00024 } \ -00025 } while (0) +00037 /* Example error checking macro. Include after each UM call. */ +00038 #define EX_LBM_CHK(err) do { \ +00039 if ((err) < 0) { \ +00040 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ +00041 __FILE__, __LINE__, lbm_errmsg()); \ +00042 exit(1); \ +00043 } \ +00044 } while (0)@@ -107,20 +107,20 @@Includes
A small effort was made to provide a some portability between Unix and Windows. For example:
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>diff --git a/multi_context/c/multi_context_c.slsrc b/multi_context/c/multi_context_c.slsrc index 2587856..fc7cb35 100644 --- a/multi_context/c/multi_context_c.slsrc +++ b/multi_context/c/multi_context_c.slsrc @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* multi_context.c - see http://ultramessaging.github.io/UMExamples/multi_context/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -20,11 +39,11 @@ /* =semlit,block,error_check=*/ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* =semlit,endblock,error_check=*/ @@ -33,33 +52,34 @@ #define LBM_APPLICATION_NAME "main" /* =semlit,endblock,define_configs=*/ -main() + +int main(int argc, char **argv) { - /* =semlit,block,vars=*/ - lbm_context_t *ctx_1; /* Context object */ - lbm_context_attr_t * cattr_1; /* pointer to context attribute object */ - lbm_context_t *ctx_2; /* Context object */ - lbm_context_attr_t * cattr_2; /* pointer to context attribute object */ - int err; /* Used for checking API return codes */ - /* =semlit,endblock,vars=*/ + /* =semlit,block,vars=*/ + lbm_context_t *ctx_1; /* Context object */ + lbm_context_attr_t * cattr_1; /* pointer to context attribute object */ + lbm_context_t *ctx_2; /* Context object */ + lbm_context_attr_t * cattr_2; /* pointer to context attribute object */ + int err; + /* =semlit,endblock,vars=*/ - /* =semlit,block,init_win=*/ + /* =semlit,block,init_win=*/ #if defined(_WIN32) - /* 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); - } + /* 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 - /* =semlit,endblock,init_win=*/ + /* =semlit,endblock,init_win=*/ - /* =semlit,block,xml_file=*/ + /* =semlit,block,xml_file=*/ err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); - EX_LBM_CHK(err); - /* =semlit,endblock,xml_file=*/ + EX_LBM_CHK(err); + /* =semlit,endblock,xml_file=*/ /* =semlit,block,ctx_1=*/ err = lbm_context_attr_create_from_xml(&cattr_1, "TRD1"); @@ -85,4 +105,5 @@ main() #if defined(_MSC_VER) WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/multi_context/c/multi_context_c.slsrc.html b/multi_context/c/multi_context_c.slsrc.html index b54ca7c..20d1c49 100644 --- a/multi_context/c/multi_context_c.slsrc.html +++ b/multi_context/c/multi_context_c.slsrc.html @@ -18,77 +18,117 @@ diff --git a/no_source_notify/c/no_source_notify.c b/no_source_notify/c/no_source_notify.c index 1ee9508..de9304e 100644 --- a/no_source_notify/c/no_source_notify.c +++ b/no_source_notify/c/no_source_notify.c @@ -1,4 +1,23 @@ -/* no_source_notify.c - http://ultramessaging.github.io/UMExamples */ +/* no_source_notify.c - see http://ultramessaging.github.io/UMExamples/no_source_notify/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 -00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 00048 -00049 -00050 +00049 +00050 00051 -00052 -00053 -00054 -00055 -00056 +00052 +00053 +00054 +00055 +00056 00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 00068 -00069 -00070 +00069 +00070 00071 -00072 - /* Code Disclaimer? */ +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 + /* multi_context.c - see http://ultramessaging.github.io/UMExamples/multi_context/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -107,33 +147,34 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) #define LBM_CONFIG_XML_FILE "multi_context_config.xml" #define LBM_APPLICATION_NAME "main" - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx_1; /* Context object */ - lbm_context_attr_t * cattr_1; /* pointer to context attribute object */ - lbm_context_t *ctx_2; /* Context object */ - lbm_context_attr_t * cattr_2; /* pointer to context attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx_1; /* Context object */ + lbm_context_attr_t * cattr_1; /* pointer to context attribute object */ + lbm_context_t *ctx_2; /* Context object */ + lbm_context_attr_t * cattr_2; /* pointer to context attribute object */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 err = lbm_config_xml_file((const char *)LBM_CONFIG_XML_FILE, (const char *)LBM_APPLICATION_NAME); @@ -159,7 +200,8 @@ #if defined(_MSC_VER) WSACleanup(); #endif - } + return 0; + } /* main */ @@ -17,22 +36,21 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) #define NO_SOURCE_QUERIES "25" int no_source = 0; + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_NO_SOURCE_NOTIFICATION: printf("[%s], no sources found for topic after %s queries\n", msg->topic_name, NO_SOURCE_QUERIES); @@ -43,16 +61,16 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } return 0; -} +} /* rcv_handle_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to topics. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -70,13 +88,13 @@ main() EX_LBM_CHK(err); err = lbm_rcv_topic_attr_create(&rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES); EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -93,4 +111,6 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif + + return 0; } /* main */ diff --git a/no_source_notify/c/no_source_notify.sldoc.html b/no_source_notify/c/no_source_notify.sldoc.html index 84af21f..8e49f26 100644 --- a/no_source_notify/c/no_source_notify.sldoc.html +++ b/no_source_notify/c/no_source_notify.sldoc.html @@ -34,14 +34,14 @@ Variables
First there is a macro to define the number of queries threshold before the notification is executed
-00027 #define NO_SOURCE_QUERIES "25" +00046 #define NO_SOURCE_QUERIES "25"Next there is the global flag variable which the main application thread will wait on.
-00029 int no_source = 0; +00048 int no_source = 0;@@ -60,8 +60,8 @@Configure the Threshold Attribute
The attribute can be configured programatically like so:-00075 err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES); -00076 EX_LBM_CHK(err); +00093 err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES); +00094 EX_LBM_CHK(err);@@ -72,10 +72,10 @@Handle the Notification Callback
we will simply print a message to stdout.-00037 case LBM_MSG_NO_SOURCE_NOTIFICATION: -00038 printf("[%s], no sources found for topic after %s queries\n", msg->topic_name, NO_SOURCE_QUERIES); -00039 no_source++; -00040 break; +00055 case LBM_MSG_NO_SOURCE_NOTIFICATION: +00056 printf("[%s], no sources found for topic after %s queries\n", msg->topic_name, NO_SOURCE_QUERIES); +00057 no_source++; +00058 break;@@ -84,20 +84,20 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>@@ -105,16 +105,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00057 #if defined(_WIN32) -00058 /* windows-specific code */ -00059 WSADATA wsadata; -00060 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00061 if (wsStat != 0) -00062 { -00063 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00064 exit(1); -00065 } -00066 #endif +00075 #if defined(_WIN32) +00076 /* windows-specific code */ +00077 WSADATA wsadata; +00078 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00079 if (wsStat != 0) +00080 { +00081 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00082 exit(1); +00083 } +00084 #endifdiff --git a/no_source_notify/c/no_source_notify_c.slsrc b/no_source_notify/c/no_source_notify_c.slsrc index 4cbda8d..f1c789d 100644 --- a/no_source_notify/c/no_source_notify_c.slsrc +++ b/no_source_notify/c/no_source_notify_c.slsrc @@ -1,4 +1,23 @@ -/* no_source_notify.c - http://ultramessaging.github.io/UMExamples */ +/* no_source_notify.c - see http://ultramessaging.github.io/UMExamples/no_source_notify/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -19,11 +38,11 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* =semlit,block,num_queries=*/ @@ -34,11 +53,10 @@ int no_source = 0; /* =semlit,endblock,no_source_var=*/ + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { /* =semlit,block,no_source_cb=*/ case LBM_MSG_NO_SOURCE_NOTIFICATION: @@ -51,16 +69,16 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } return 0; -} +} /* rcv_handle_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to topics. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + int err; /* =semlit,block,windows=*/ #if defined(_WIN32) @@ -80,7 +98,7 @@ main() EX_LBM_CHK(err); err = lbm_rcv_topic_attr_create(&rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); /* =semlit,block,set_attr=*/ err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES); @@ -88,7 +106,7 @@ main() /* =semlit,endblock,set_attr=*/ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -105,4 +123,6 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif + + return 0; } /* main */ diff --git a/no_source_notify/c/no_source_notify_c.slsrc.html b/no_source_notify/c/no_source_notify_c.slsrc.html index 151081d..a11afc4 100644 --- a/no_source_notify/c/no_source_notify_c.slsrc.html +++ b/no_source_notify/c/no_source_notify_c.slsrc.html @@ -18,70 +18,70 @@ diff --git a/quorum_state/c/quorum_state.c b/quorum_state/c/quorum_state.c index 6dcc3aa..587afa9 100644 --- a/quorum_state/c/quorum_state.c +++ b/quorum_state/c/quorum_state.c @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* quorum_state.c - see http://ultramessaging.github.io/UMExamples/quorum_state/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 00036 -00037 -00038 -00039 -00040 +00037 +00038 +00039 +00040 00041 00042 00043 00044 00045 -00046 +00046 00047 -00048 +00048 00049 00050 00051 00052 00053 00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 00067 00068 00069 @@ -90,16 +90,16 @@ 00072 00073 00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 00085 00086 00087 @@ -108,11 +108,50 @@ 00090 00091 00092 -00093 -00094 +00093 +00094 00095 00096 - /* no_source_notify.c - http://ultramessaging.github.io/UMExamples */ +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 + /* no_source_notify.c - see http://ultramessaging.github.io/UMExamples/no_source_notify/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -131,22 +170,21 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) #define NO_SOURCE_QUERIES "25" int no_source = 0; + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_NO_SOURCE_NOTIFICATION: printf("[%s], no sources found for topic after %s queries\n", msg->topic_name, NO_SOURCE_QUERIES); @@ -157,16 +195,16 @@ break; } return 0; - } + } /* rcv_handle_msg */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to topics. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -184,13 +222,13 @@ EX_LBM_CHK(err); err = lbm_rcv_topic_attr_create(&rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_topic_attr_str_setopt(rattr, "resolution_no_source_notification_threshold", NO_SOURCE_QUERIES); EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -207,6 +245,8 @@ /* Windows-specific cleanup overhead */ WSACleanup(); #endif + + return 0; } /* main */ #include @@ -22,8 +41,18 @@ # define SLEEP_SEC(x) sleep(x) #endif +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + int src_ready = 0; + /* Source event handler callback (passed into lbm_src_create()) */ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) { @@ -42,82 +71,56 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) } } return 0; -} +} /* handle_src_event */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_topic_t *topic; /* Topic object */ - lbm_src_t *src; /* Source object */ - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_topic_t *topic; /* Topic object */ + lbm_src_t *src; /* Source object */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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); - } - - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - - if (lbm_src_topic_attr_create(&tattr) != 0) - { - fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); - exit(1); - } - - /* Assuming there is a store running on the localhost at port 29999 */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); + + /* Assuming there is a store running on the localhost at port 29999 */ + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); + EX_LBM_CHK(err); /* Need to set store behavior to Quorum-Consensus */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store_behavior: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); - if (err) - { - printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); + EX_LBM_CHK(err); - err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); - if (err) - { - printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); + EX_LBM_CHK(err); while(1) { if (src_ready) { - if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); + if (err == LBM_FAILURE) { - /* Assume EWOULDBLOCK and wait */ + /* Assume EWOULDBLOCK, wait, and retry. */ SLEEP_SEC(1); } } @@ -128,4 +131,6 @@ main() SLEEP_SEC(1); } } -} + + return 0; +} /* main */ diff --git a/quorum_state/c/quorum_state.sldoc.html b/quorum_state/c/quorum_state.sldoc.html index e35533c..e5f40fe 100644 --- a/quorum_state/c/quorum_state.sldoc.html +++ b/quorum_state/c/quorum_state.sldoc.html @@ -35,7 +35,7 @@ Create a state variable
initialize as 0, because the source upon creation will not be in a state where it can send.-00025 int src_ready = 0; +00053 int src_ready = 0;@@ -44,18 +44,8 @@Create the context
Creating a Context-00067 if (lbm_context_attr_create(&cattr) != 0) -00068 { -00069 fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); -00070 exit(1); -00071 } -00072 -00073 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00074 if (err) -00075 { -00076 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00077 exit(1); -00078 } +00096 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00097 EX_LBM_CHK(err);@@ -82,39 +72,22 @@Create Source
-00080 if (lbm_src_topic_attr_create(&tattr) != 0) -00081 { -00082 fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); -00083 exit(1); -00084 } -00085 -00086 /* Assuming there is a store running on the localhost at port 29999 */ -00087 if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) -00088 { -00089 fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store: %s\n", lbm_errmsg()); -00090 exit(1); -00091 } -00092 -00093 /* Need to set store behavior to Quorum-Consensus */ -00094 if (lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc") != 0 ) -00095 { -00096 fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store_behavior: %s\n", lbm_errmsg()); -00097 exit(1); -00098 } -00099 -00100 err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); -00101 if (err) -00102 { -00103 printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); -00104 exit(1); -00105 } -00106 -00107 err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); -00108 if (err) -00109 { -00110 printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); -00111 exit(1); -00112 } +00099 err = lbm_src_topic_attr_create(&tattr); +00100 EX_LBM_CHK(err); +00101 +00102 /* Assuming there is a store running on the localhost at port 29999 */ +00103 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); +00104 EX_LBM_CHK(err); +00105 +00106 /* Need to set store behavior to Quorum-Consensus */ +00107 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); +00108 EX_LBM_CHK(err); +00109 +00110 err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); +00111 EX_LBM_CHK(err); +00112 +00113 err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); +00114 EX_LBM_CHK(err);@@ -156,11 +129,11 @@Setting the state
store. Setting the state in the registration complete event can look like this:-00031 case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: -00032 { -00033 src_ready = 1; -00034 break; -00035 } +00060 case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: +00061 { +00062 src_ready = 1; +00063 break; +00064 }@@ -170,13 +143,13 @@Setting the state
determine if quorum has actually been lost, like so:-00036 case LBM_SRC_EVENT_UME_STORE_UNRESPONSIVE: -00037 { -00038 const char *infostr = (const char *)ed; -00039 if (strstr(infostr, "quorum lost") != NULL) -00040 src_ready = 0; -00041 break; -00042 } +00065 case LBM_SRC_EVENT_UME_STORE_UNRESPONSIVE: +00066 { +00067 const char *infostr = (const char *)ed; +00068 if (strstr(infostr, "quorum lost") != NULL) +00069 src_ready = 0; +00070 break; +00071 }@@ -187,7 +160,7 @@Main Send Loop
to stdout when the source is not in the ready state-00114 while(1) +00116 while(1)@@ -197,20 +170,21 @@Send a Message
notified via the unresponsive source event; in either case the source cannot send.-00116 if (src_ready) -00117 { -00118 if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) -00119 { -00120 /* Assume EWOULDBLOCK and wait */ -00121 SLEEP_SEC(1); -00122 } -00123 } -00124 else -00125 { -00126 /* Print a warning that the source is not ready and sleep */ -00127 printf("Source is not ready to send (no quorum)\n"); -00128 SLEEP_SEC(1); -00129 } +00118 if (src_ready) +00119 { +00120 err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); +00121 if (err == LBM_FAILURE) +00122 { +00123 /* Assume EWOULDBLOCK, wait, and retry. */ +00124 SLEEP_SEC(1); +00125 } +00126 } +00127 else +00128 { +00129 /* Print a warning that the source is not ready and sleep */ +00130 printf("Source is not ready to send (no quorum)\n"); +00131 SLEEP_SEC(1); +00132 }@@ -218,21 +192,21 @@Includes
Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
-00003 #include <stdio.h> -00004 #include <string.h> -00005 -00006 #if defined(_MSC_VER) -00007 /* Windows-only includes */ -00008 #include <winsock2.h> -00009 #define SLEEP(s) Sleep((s)*1000) -00010 #else -00011 /* Unix-only includes */ -00012 #include <stdlib.h> -00013 #include <unistd.h> -00014 #define SLEEP(s) sleep(s) -00015 #endif -00016 -00017 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 #include <string.h> +00024 +00025 #if defined(_MSC_VER) +00026 /* Windows-only includes */ +00027 #include <winsock2.h> +00028 #define SLEEP(s) Sleep((s)*1000) +00029 #else +00030 /* Unix-only includes */ +00031 #include <stdlib.h> +00032 #include <unistd.h> +00033 #define SLEEP(s) sleep(s) +00034 #endif +00035 +00036 #include <lbm/lbm.h>@@ -241,11 +215,11 @@Sleep helper function
sleep() for any number of seconds.-00019 #if defined(_WIN32) -00020 # define SLEEP_SEC(x) Sleep((x)*1000) -00021 #else -00022 # define SLEEP_SEC(x) sleep(x) -00023 #endif +00038 #if defined(_WIN32) +00039 # define SLEEP_SEC(x) Sleep((x)*1000) +00040 #else +00041 # define SLEEP_SEC(x) sleep(x) +00042 #endifdiff --git a/quorum_state/c/quorum_state_c.slsrc b/quorum_state/c/quorum_state_c.slsrc index 67be15c..ffd5865 100644 --- a/quorum_state/c/quorum_state_c.slsrc +++ b/quorum_state/c/quorum_state_c.slsrc @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* quorum_state.c - see http://ultramessaging.github.io/UMExamples/quorum_state/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -26,10 +45,20 @@ #endif /* =semlit,endblock,sleep_macro=*/ +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + /* =semlit,block,src_ready_int=*/ int src_ready = 0; /* =semlit,endblock,src_ready_int=*/ + /* Source event handler callback (passed into lbm_src_create()) */ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) { @@ -52,91 +81,65 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) /* =semlit,endblock,unresponsive=*/ } return 0; -} +} /* handle_src_event */ -main() + +int main(int argc, char **argv) { - /* =semlit,block,variables=*/ - lbm_context_t *ctx; /* Context object */ - lbm_topic_t *topic; /* Topic object */ - lbm_src_t *src; /* Source object */ - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ - /* =semlit,endblock,variables=*/ + /* =semlit,block,variables=*/ + lbm_context_t *ctx; /* Context object */ + lbm_topic_t *topic; /* Topic object */ + lbm_src_t *src; /* Source object */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + int err; + /* =semlit,endblock,variables=*/ #if defined(_WIN32) - /* 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); - } + /* 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 - /* =semlit,block,init_create_context=*/ - if (lbm_context_attr_create(&cattr) != 0) - { - fprintf(stderr, "lbm_context_attr_create: %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); - } - /* =semlit,endblock,init_create_context=*/ - - /* =semlit,block,init_create_source=*/ - if (lbm_src_topic_attr_create(&tattr) != 0) - { - fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); - exit(1); - } - - /* Assuming there is a store running on the localhost at port 29999 */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store: %s\n", lbm_errmsg()); - exit(1); - } + /* =semlit,block,init_create_context=*/ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,init_create_context=*/ + + /* =semlit,block,init_create_source=*/ + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); + + /* Assuming there is a store running on the localhost at port 29999 */ + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); + EX_LBM_CHK(err); /* Need to set store behavior to Quorum-Consensus */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store_behavior: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); + EX_LBM_CHK(err); + + err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); - if (err) - { - printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - - err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); - if (err) - { - printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - /* =semlit,endblock,init_create_source=*/ - - /* =semlit,block,main_send_loop=*/ + err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,init_create_source=*/ + + /* =semlit,block,main_send_loop=*/ while(1) /* =semlit,endblock,main_send_loop=*/ { /* =semlit,block,src_send=*/ if (src_ready) { - if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); + if (err == LBM_FAILURE) { - /* Assume EWOULDBLOCK and wait */ + /* Assume EWOULDBLOCK, wait, and retry. */ SLEEP_SEC(1); } } @@ -148,4 +151,6 @@ main() } /* =semlit,endblock,src_send=*/ } -} + + return 0; +} /* main */ diff --git a/quorum_state/c/quorum_state_c.slsrc.html b/quorum_state/c/quorum_state_c.slsrc.html index 83ae8fe..acb8e92 100644 --- a/quorum_state/c/quorum_state_c.slsrc.html +++ b/quorum_state/c/quorum_state_c.slsrc.html @@ -18,102 +18,102 @@ diff --git a/request_response/c/request_response.c b/request_response/c/request_response.c index 2cef5d3..cabd43a 100644 --- a/request_response/c/request_response.c +++ b/request_response/c/request_response.c @@ -1,4 +1,23 @@ -/* request_response.c - http://ultramessaging.github.io/UMExamples */ +/* request_response.c - see http://ultramessaging.github.io/UMExamples/request_response/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 -00017 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 +00017 00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 00043 00044 00045 00046 00047 00048 -00049 -00050 -00051 -00052 -00053 -00054 +00049 +00050 +00051 +00052 +00053 +00054 00055 00056 00057 00058 00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 00099 00100 00101 @@ -128,11 +128,11 @@ 00110 00111 00112 -00113 -00114 +00113 +00114 00115 -00116 -00117 +00116 +00117 00118 00119 00120 @@ -145,9 +145,33 @@ 00127 00128 00129 -00130 -00131 - /* Code Disclaimer? */ +00130 +00131 +00132 +00133 +00134 +00135 +00136 + /* quorum_state.c - see http://ultramessaging.github.io/UMExamples/quorum_state/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> #include <string.h> @@ -171,8 +195,18 @@ # define SLEEP_SEC(x) sleep(x) #endif + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + int src_ready = 0; + /* Source event handler callback (passed into lbm_src_create()) */ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) { @@ -191,82 +225,56 @@ } } return 0; - } + } /* handle_src_event */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_topic_t *topic; /* Topic object */ - lbm_src_t *src; /* Source object */ - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_topic_t *topic; /* Topic object */ + lbm_src_t *src; /* Source object */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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); - } - - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - if (lbm_src_topic_attr_create(&tattr) != 0) - { - fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); - /* Assuming there is a store running on the localhost at port 29999 */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store: %s\n", lbm_errmsg()); - exit(1); - } + /* Assuming there is a store running on the localhost at port 29999 */ + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", "127.0.0.1:29999"); + EX_LBM_CHK(err); /* Need to set store behavior to Quorum-Consensus */ - if (lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc") != 0 ) - { - fprintf(stderr, "lbm_src_topic_attr_str_setopt:ume_store_behavior: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); - if (err) - { - printf("lbm_src_topic_alloc - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_src_topic_alloc(&topic, ctx, "test.topic", tattr); + EX_LBM_CHK(err); - err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); - if (err) - { - printf("lbm_src_create - line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_src_create(&src, ctx, topic, handle_src_event, NULL, NULL); + EX_LBM_CHK(err); while(1) { if (src_ready) { - if (lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + err = lbm_src_send(src, "test", 4, LBM_SRC_NONBLOCK); + if (err == LBM_FAILURE) { - /* Assume EWOULDBLOCK and wait */ + /* Assume EWOULDBLOCK, wait, and retry. */ SLEEP_SEC(1); } } @@ -277,7 +285,9 @@ SLEEP_SEC(1); } } - } + + return 0; + } /* main */ @@ -18,15 +37,16 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* Global var used to indicate that the application can exit after response received */ int run = 1; + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { @@ -39,47 +59,47 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) EX_LBM_CHK(err); break; } -} + return 0; +} /* rcv_handle_msg */ + /* Callback used to handle response message */ int handle_response(lbm_request_t *req, lbm_msg_t *msg, void *clientd) { - switch (msg->type) { - case LBM_MSG_RESPONSE: + switch (msg->type) { + case LBM_MSG_RESPONSE: printf("LBM_MSG_RESPONSE received\n"); run = 0; break; } -} + return 0; +} /* handle_response */ + -main() +int main(int argc, char **argv) { lbm_context_t *ctx; /* Context object */ lbm_topic_t *stopic; /* Source Topic object */ lbm_src_t *src; /* Source object */ lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ lbm_topic_t *rtopic; /* Receiver Topic object */ lbm_request_t *req; /* Request object */ - int err; /* Used for checking API return codes */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 context atrributes and create context */ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); /* Create receiver for receiving request and sending response */ @@ -92,12 +112,12 @@ main() /* Create source for sending request */ err = lbm_src_topic_attr_create(&tattr); EX_LBM_CHK(err); - + err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_src_topic_attr_delete(tattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_src_create(&src, ctx, stopic, NULL, NULL, NULL); EX_LBM_CHK(err); @@ -106,24 +126,26 @@ main() EX_LBM_CHK(err); while (run) { /* loop until response received */ - SLEEP(1); - } + SLEEP(1); + } /* Clean up */ err = lbm_request_delete(req); EX_LBM_CHK(err); - err = lbm_src_delete(src); - EX_LBM_CHK(err); + err = lbm_src_delete(src); + EX_LBM_CHK(err); err = lbm_rcv_delete(rcv); EX_LBM_CHK(err); - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif + + return 0; } /* main */ diff --git a/request_response/c/request_response.sldoc.html b/request_response/c/request_response.sldoc.html index aeee175..bbba34c 100644 --- a/request_response/c/request_response.sldoc.html +++ b/request_response/c/request_response.sldoc.html @@ -32,15 +32,14 @@ Declare Variables
API calls-00057 lbm_context_t *ctx; /* Context object */ -00058 lbm_topic_t *stopic; /* Source Topic object */ -00059 lbm_src_t *src; /* Source object */ -00060 lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ -00061 lbm_context_attr_t * cattr; /* Context attribute object */ -00062 lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ -00063 lbm_topic_t *rtopic; /* Receiver Topic object */ -00064 lbm_request_t *req; /* Request object */ -00065 int err; /* Used for checking API return codes */ +00081 lbm_context_t *ctx; /* Context object */ +00082 lbm_topic_t *stopic; /* Source Topic object */ +00083 lbm_src_t *src; /* Source object */ +00084 lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ +00085 lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ +00086 lbm_topic_t *rtopic; /* Receiver Topic object */ +00087 lbm_request_t *req; /* Request object */ +00088 int err;@@ -49,12 +48,12 @@Create Receiver and Message Callback Function
object (rcv). Note when calling the receiver create API, lbm_rcv_create, the fourth parameter is rcv_handle_message.-00085 /* Create receiver for receiving request and sending response */ -00086 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); -00087 EX_LBM_CHK(err); -00088 -00089 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); -00090 EX_LBM_CHK(err); +00105 /* Create receiver for receiving request and sending response */ +00106 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); +00107 EX_LBM_CHK(err); +00108 +00109 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); +00110 EX_LBM_CHK(err);@@ -66,18 +65,20 @@Create Receiver and Message Callback Function
handled.-00031 int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) -00032 { -00033 int err; -00034 -00035 switch (msg->type) { -00036 case LBM_MSG_REQUEST: -00037 printf("LBM_MSG_REQUEST received\n"); -00038 err = lbm_send_response(msg->response, "response", 8, LBM_SRC_NONBLOCK); -00039 EX_LBM_CHK(err); -00040 break; -00041 } -00042 } +00050 /* Callback used to handle request message for receiver */ +00051 int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +00052 { +00053 int err; +00054 +00055 switch (msg->type) { +00056 case LBM_MSG_REQUEST: +00057 printf("LBM_MSG_REQUEST received\n"); +00058 err = lbm_send_response(msg->response, "response", 8, LBM_SRC_NONBLOCK); +00059 EX_LBM_CHK(err); +00060 break; +00061 } +00062 return 0; +00063 } /* rcv_handle_msg */@@ -86,17 +87,17 @@Create source, Send Request and Response Handler Callback
send the request:-00093 err = lbm_src_topic_attr_create(&tattr); -00094 EX_LBM_CHK(err); -00095 -00096 err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); -00097 EX_LBM_CHK(err); -00098 -00099 err = lbm_src_topic_attr_delete(tattr); -00100 EX_LBM_CHK(err); -00101 -00102 err = lbm_src_create(&src, ctx, stopic, NULL, NULL, NULL); -00103 EX_LBM_CHK(err); +00113 err = lbm_src_topic_attr_create(&tattr); +00114 EX_LBM_CHK(err); +00115 +00116 err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); +00117 EX_LBM_CHK(err); +00118 +00119 err = lbm_src_topic_attr_delete(tattr); +00120 EX_LBM_CHK(err); +00121 +00122 err = lbm_src_create(&src, ctx, stopic, NULL, NULL, NULL); +00123 EX_LBM_CHK(err);@@ -106,8 +107,8 @@Create source, Send Request and Response Handler Callback
handle_response:-00105 err = lbm_send_request(&req, src, "request", 7, handle_response, NULL, NULL, 0); -00106 EX_LBM_CHK(err); +00125 err = lbm_send_request(&req, src, "request", 7, handle_response, NULL, NULL, 0); +00126 EX_LBM_CHK(err);@@ -116,15 +117,17 @@Create source, Send Request and Response Handler Callback
lbm_msg_t struct.-00045 int handle_response(lbm_request_t *req, lbm_msg_t *msg, void *clientd) -00046 { -00047 switch (msg->type) { -00048 case LBM_MSG_RESPONSE: -00049 printf("LBM_MSG_RESPONSE received\n"); -00050 run = 0; -00051 break; -00052 } -00053 } +00066 /* Callback used to handle response message */ +00067 int handle_response(lbm_request_t *req, lbm_msg_t *msg, void *clientd) +00068 { +00069 switch (msg->type) { +00070 case LBM_MSG_RESPONSE: +00071 printf("LBM_MSG_RESPONSE received\n"); +00072 run = 0; +00073 break; +00074 } +00075 return 0; +00076 } /* handle_response */@@ -138,8 +141,8 @@Send Response
on the context thread can result in application deadlock.-00038 err = lbm_send_response(msg->response, "response", 8, LBM_SRC_NONBLOCK); -00039 EX_LBM_CHK(err); +00058 err = lbm_send_response(msg->response, "response", 8, LBM_SRC_NONBLOCK); +00059 EX_LBM_CHK(err);@@ -149,9 +152,9 @@Main Loop
will be set to 0 and the loop will break-00108 while (run) { /* loop until response received */ -00109 SLEEP(1); -00110 } +00128 while (run) { /* loop until response received */ +00129 SLEEP(1); +00130 }@@ -161,22 +164,22 @@Cleanup
when not properly cleaned.-00113 err = lbm_request_delete(req); -00114 EX_LBM_CHK(err); +00133 err = lbm_request_delete(req); +00134 EX_LBM_CHK(err);Once the request is deleted, the source, receiver and context can be deleted
-00116 err = lbm_src_delete(src); -00117 EX_LBM_CHK(err); -00118 -00119 err = lbm_rcv_delete(rcv); -00120 EX_LBM_CHK(err); -00121 -00122 err = lbm_context_delete(ctx); -00123 EX_LBM_CHK(err); +00136 err = lbm_src_delete(src); +00137 EX_LBM_CHK(err); +00138 +00139 err = lbm_rcv_delete(rcv); +00140 EX_LBM_CHK(err); +00141 +00142 err = lbm_context_delete(ctx); +00143 EX_LBM_CHK(err);@@ -186,14 +189,14 @@Error Checking
print a message and exit the program:-00018 /* Example error checking macro. Include after each UM call. */ -00019 #define EX_LBM_CHK(err) do { \ -00020 if ((err) < 0) { \ -00021 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ -00022 __FILE__, __LINE__, lbm_errmsg()); \ -00023 exit(1); \ -00024 } \ -00025 } while (0) +00037 /* Example error checking macro. Include after each UM call. */ +00038 #define EX_LBM_CHK(err) do { \ +00039 if ((err) < 0) { \ +00040 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ +00041 __FILE__, __LINE__, lbm_errmsg()); \ +00042 exit(1); \ +00043 } \ +00044 } while (0)@@ -209,26 +212,26 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00067 #if defined(_WIN32) -00068 /* windows-specific code */ -00069 WSADATA wsadata; -00070 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00071 if (wsStat != 0) -00072 { -00073 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00074 exit(1); -00075 } -00076 #endif +00090 #if defined(_WIN32) +00091 /* windows-specific code */ +00092 WSADATA wsadata; +00093 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00094 if (wsStat != 0) +00095 { +00096 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00097 exit(1); +00098 } +00099 #endifA well-structured Windows networking application will also call WSACleanup() after before exit
-00125 #if defined(_MSC_VER) -00126 /* Windows-specific cleanup overhead */ -00127 WSACleanup(); -00128 #endif +00145 #if defined(_MSC_VER) +00146 /* Windows-specific cleanup overhead */ +00147 WSACleanup(); +00148 #endif@@ -236,20 +239,20 @@Includes
A small effort was made to provide a some portability between Unix and Windows. For example:
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>diff --git a/request_response/c/request_response_c.slsrc b/request_response/c/request_response_c.slsrc index 45bf245..d90b7fc 100644 --- a/request_response/c/request_response_c.slsrc +++ b/request_response/c/request_response_c.slsrc @@ -1,4 +1,23 @@ -/* request_response.c - http://ultramessaging.github.io/UMExamples */ +/* request_response.c - see http://ultramessaging.github.io/UMExamples/request_response/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -21,18 +40,19 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* =semlit,endblock,error_check=*/ /* Global var used to indicate that the application can exit after response received */ int run = 1; -/* Callback used to handle request message for receiver */ + /* =semlit,block,rcv_cb=*/ +/* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { int err; @@ -46,54 +66,54 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) /* =semlit,endblock,send_resp=*/ break; } -} + return 0; +} /* rcv_handle_msg */ /* =semlit,endblock,rcv_cb=*/ -/* Callback used to handle response message */ + /* =semlit,block,resp_cb=*/ +/* Callback used to handle response message */ int handle_response(lbm_request_t *req, lbm_msg_t *msg, void *clientd) { - switch (msg->type) { - case LBM_MSG_RESPONSE: + switch (msg->type) { + case LBM_MSG_RESPONSE: printf("LBM_MSG_RESPONSE received\n"); run = 0; break; } -} + return 0; +} /* handle_response */ /* =semlit,endblock,resp_cb=*/ -main() + +int main(int argc, char **argv) { /* =semlit,block,vars=*/ lbm_context_t *ctx; /* Context object */ lbm_topic_t *stopic; /* Source Topic object */ lbm_src_t *src; /* Source object */ lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ lbm_topic_t *rtopic; /* Receiver Topic object */ lbm_request_t *req; /* Request object */ - int err; /* Used for checking API return codes */ + int err; /* =semlit,endblock,vars=*/ /* =semlit,block,init_win=*/ #if defined(_WIN32) - /* 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); - } + /* 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 /* =semlit,endblock,init_win=*/ - + /* Initialize context atrributes and create context */ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); /* =semlit,block,create_rcv=*/ @@ -109,12 +129,12 @@ main() /* =semlit,block,create_src=*/ err = lbm_src_topic_attr_create(&tattr); EX_LBM_CHK(err); - + err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_src_topic_attr_delete(tattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_src_create(&src, ctx, stopic, NULL, NULL, NULL); EX_LBM_CHK(err); @@ -127,8 +147,8 @@ main() /* =semlit,block,loop=*/ while (run) { /* loop until response received */ - SLEEP(1); - } + SLEEP(1); + } /* =semlit,endblock,loop=*/ /* Clean up */ @@ -138,20 +158,22 @@ main() /* =semlit,endblock,del_req=*/ /* =semlit,block,clean=*/ - err = lbm_src_delete(src); - EX_LBM_CHK(err); + err = lbm_src_delete(src); + EX_LBM_CHK(err); err = lbm_rcv_delete(rcv); EX_LBM_CHK(err); - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); /* =semlit,endblock,clean=*/ /* =semlit,block,clean_win=*/ #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif /* =semlit,endblock,clean_win=*/ + + return 0; } /* main */ diff --git a/request_response/c/request_response_c.slsrc.html b/request_response/c/request_response_c.slsrc.html index 6c49fb6..8cdb365 100644 --- a/request_response/c/request_response_c.slsrc.html +++ b/request_response/c/request_response_c.slsrc.html @@ -18,134 +18,175 @@ diff --git a/schedule_timers/c/schedule_timers.c b/schedule_timers/c/schedule_timers.c index bd5d6db..05d3f3e 100644 --- a/schedule_timers/c/schedule_timers.c +++ b/schedule_timers/c/schedule_timers.c @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* schedule_timers.c - see http://ultramessaging.github.io/UMExamples/schedule_timers/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 -00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 00077 00078 00079 00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 -00099 -00100 -00101 -00102 -00103 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 00104 -00105 -00106 -00107 -00108 -00109 -00110 +00105 +00106 +00107 +00108 +00109 +00110 00111 00112 -00113 -00114 -00115 -00116 -00117 -00118 -00119 -00120 -00121 -00122 -00123 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 00124 -00125 -00126 -00127 -00128 -00129 - /* request_response.c - http://ultramessaging.github.io/UMExamples */ +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 +00149 +00150 +00151 + /* request_response.c - see http://ultramessaging.github.io/UMExamples/request_response/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -165,17 +206,18 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ + exit(1); \ } \ } while (0) /* Global var used to indicate that the application can exit after response received */ int run = 1; - /* Callback used to handle request message for receiver */ - int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) + + /* Callback used to handle request message for receiver */ + int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { int err; @@ -186,47 +228,47 @@ EX_LBM_CHK(err); break; } - } + return 0; + } /* rcv_handle_msg */ + - /* Callback used to handle response message */ - int handle_response(lbm_request_t *req, lbm_msg_t *msg, void *clientd) + /* Callback used to handle response message */ + int handle_response(lbm_request_t *req, lbm_msg_t *msg, void *clientd) { - switch (msg->type) { - case LBM_MSG_RESPONSE: + switch (msg->type) { + case LBM_MSG_RESPONSE: printf("LBM_MSG_RESPONSE received\n"); run = 0; break; } - } + return 0; + } /* handle_response */ - main() + + int main(int argc, char **argv) { lbm_context_t *ctx; /* Context object */ lbm_topic_t *stopic; /* Source Topic object */ lbm_src_t *src; /* Source object */ lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_context_attr_t * cattr; /* Context attribute object */ lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ lbm_topic_t *rtopic; /* Receiver Topic object */ lbm_request_t *req; /* Request object */ - int err; /* Used for checking API return codes */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 context atrributes and create context */ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); /* Create receiver for receiving request and sending response */ @@ -239,7 +281,7 @@ /* Create source for sending request */ err = lbm_src_topic_attr_create(&tattr); EX_LBM_CHK(err); - + err = lbm_src_topic_alloc(&stopic, ctx, "test.topic", tattr); EX_LBM_CHK(err); @@ -253,7 +295,7 @@ EX_LBM_CHK(err); while (run) { /* loop until response received */ - SLEEP(1); + SLEEP(1); } /* Clean up */ @@ -273,6 +315,8 @@ /* Windows-specific cleanup overhead */ WSACleanup(); #endif + + return 0; } /* main */ @@ -24,45 +43,45 @@ } \ } while (0) -int wait = 1; +int wait_flag = 1; + /* Timer callback function */ int sample_timer_handler(lbm_context_t *ctx, const void *clientd) { printf("Timer executed. Set wait to 0 so application can cleanly exit\n"); - wait = 0; -} + wait_flag = 0; + + return 0; +} /* sample_timer_handler */ + -main() +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ - int timer_id; /* Used to get timer id from schedule API */ + lbm_context_t *ctx; /* Context object */ + int timer_id; /* Used to get timer id from schedule API */ + int err; /* Initialize context atrributes and create context */ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); - if ((timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000)) == -1) { - fprintf(stderr, "%s:%d, lbm error: '%s'\n", __FILE__, __LINE__, lbm_errmsg()); - exit(1); - } + /* Be careful! lbm_schedule_timer() returns >0 on success. */ + timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000); + EX_LBM_CHK(timer_id); /* Now wait for callback to end the wait and close the application */ - while (wait) + while (wait_flag) SLEEP(1); /* Clean up */ err = lbm_context_delete(ctx); EX_LBM_CHK(err); - + #if defined(_MSC_VER) /* Windows-specific cleanup overhead */ WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/schedule_timers/c/schedule_timers.sldoc b/schedule_timers/c/schedule_timers.sldoc index 268c5ef..d60ae2d 100644 --- a/schedule_timers/c/schedule_timers.sldoc +++ b/schedule_timers/c/schedule_timers.sldoc @@ -19,14 +19,14 @@ The callback function defined below is the application callback that will be invoked when the scheduled timer expires. This callback will be executed on the UM context thread (at least for the purpose of this example it will be executed on the context thread.
=semlit,insert,timer_cb= -Note that inside the callback, the global "wait" variable is set to 0, this allows the main thread to stop tight-looping and exit.
+Note that inside the callback, the global "wait_flag" variable is set to 0, this allows the main thread to stop tight-looping and exit.
Scheduling the Timer Callback
Here the application is actually scheduling the callback timer, set to be executed in 1000 milliseconds. The return value should be saved by the application in the event that the application wishes to cancel the timer before it executes. Special care must be taken when cancelling timer callback, for more information please see For the purpose of this example application, it is using the global variable "wait_flag" as a semaphore essentially. Once the timer executes, wait will be set to 0 and the application can cleanly exit by deleting the context.
=semlit,insert,wait=Error Checking
diff --git a/schedule_timers/c/schedule_timers.sldoc.html b/schedule_timers/c/schedule_timers.sldoc.html index 2ed536f..6b63cfd 100644 --- a/schedule_timers/c/schedule_timers.sldoc.html +++ b/schedule_timers/c/schedule_timers.sldoc.html @@ -24,11 +24,8 @@Initializing the Context
Creating a Context-00044 err = lbm_context_attr_create(&cattr); -00045 EX_LBM_CHK(err); -00046 -00047 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00048 EX_LBM_CHK(err); +00066 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00067 EX_LBM_CHK(err);@@ -37,35 +34,37 @@Creating a Callback
be executed on the UM context thread (at least for the purpose of this example it will be executed on the context thread.-00030 int sample_timer_handler(lbm_context_t *ctx, const void *clientd) -00031 { -00032 printf("Timer executed. Set wait to 0 so application can cleanly exit\n"); -00033 wait = 0; -00034 } +00049 /* Timer callback function */ +00050 int sample_timer_handler(lbm_context_t *ctx, const void *clientd) +00051 { +00052 printf("Timer executed. Set wait to 0 so application can cleanly exit\n"); +00053 wait_flag = 0; +00054 +00055 return 0; +00056 } /* sample_timer_handler */-Note that inside the callback, the global "wait" variable is set to 0, this allows the main thread to stop tight-looping and exit.
+Note that inside the callback, the global "wait_flag" variable is set to 0, this allows the main thread to stop tight-looping and exit.
Scheduling the Timer Callback
Here the application is actually scheduling the callback timer, set to be executed in 1000 milliseconds. The return value should be saved by the application in the event that the application wishes to cancel the timer before it executes. Special care must be taken when cancelling timer callback, for more information please see
-00050 if ((timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000)) == -1) { -00051 fprintf(stderr, "%s:%d, lbm error: '%s'\n", __FILE__, __LINE__, lbm_errmsg()); -00052 exit(1); -00053 } +00069 /* Be careful! lbm_schedule_timer() returns >0 on success. */ +00070 timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000); +00071 EX_LBM_CHK(timer_id);Wait for Timer
-For the purpose of this example application, it is using the global variable "wait" as a semaphore essentially. Once the timer executes, wait +
For the purpose of this example application, it is using the global variable "wait_flag" as a semaphore essentially. Once the timer executes, wait will be set to 0 and the application can cleanly exit by deleting the context.
-00056 while (wait) -00057 SLEEP(1); +00074 while (wait_flag) +00075 SLEEP(1);@@ -75,13 +74,13 @@Error Checking
print a message and exit the program:-00019 #define EX_LBM_CHK(err) do { \ -00020 if ((err) < 0) { \ -00021 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ -00022 __FILE__, __LINE__, lbm_errmsg()); \ -00023 exit(1); \ -00024 } \ -00025 } while (0) +00038 #define EX_LBM_CHK(err) do { \ +00039 if ((err) < 0) { \ +00040 fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ +00041 __FILE__, __LINE__, lbm_errmsg()); \ +00042 exit(1); \ +00043 } \ +00044 } while (0)@@ -97,20 +96,20 @@Includes
Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>diff --git a/schedule_timers/c/schedule_timers_c.slsrc b/schedule_timers/c/schedule_timers_c.slsrc index eb3e2f5..f39cd45 100644 --- a/schedule_timers/c/schedule_timers_c.slsrc +++ b/schedule_timers/c/schedule_timers_c.slsrc @@ -1,4 +1,23 @@ -/* Code Disclaimer? */ +/* schedule_timers.c - see http://ultramessaging.github.io/UMExamples/schedule_timers/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -29,54 +48,54 @@ /* =semlit,endblock,error_check=*/ /* =semlit,block,int_wait=*/ -int wait = 1; +int wait_flag = 1; /* =semlit,endblock,int_wait=*/ -/* Timer callback function */ + /* =semlit,block,timer_cb=*/ +/* Timer callback function */ int sample_timer_handler(lbm_context_t *ctx, const void *clientd) { printf("Timer executed. Set wait to 0 so application can cleanly exit\n"); - wait = 0; -} + wait_flag = 0; + + return 0; +} /* sample_timer_handler */ /* =semlit,endblock,timer_cb=*/ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ - int timer_id; /* Used to get timer id from schedule API */ + lbm_context_t *ctx; /* Context object */ + int timer_id; /* Used to get timer id from schedule API */ + int err; /* Initialize context atrributes and create context */ /* =semlit,block,ctx_create=*/ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); /* =semlit,endblock,ctx_create=*/ /* =semlit,block,schedule=*/ - if ((timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000)) == -1) { - fprintf(stderr, "%s:%d, lbm error: '%s'\n", __FILE__, __LINE__, lbm_errmsg()); - exit(1); - } + /* Be careful! lbm_schedule_timer() returns >0 on success. */ + timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000); + EX_LBM_CHK(timer_id); /* =semlit,endblock,schedule=*/ /* Now wait for callback to end the wait and close the application */ /* =semlit,block,wait=*/ - while (wait) + while (wait_flag) SLEEP(1); /* =semlit,endblock,wait=*/ /* Clean up */ err = lbm_context_delete(ctx); EX_LBM_CHK(err); - + #if defined(_MSC_VER) /* Windows-specific cleanup overhead */ WSACleanup(); #endif -} + return 0; +} /* main */ diff --git a/schedule_timers/c/schedule_timers_c.slsrc.html b/schedule_timers/c/schedule_timers_c.slsrc.html index 71245cc..2c45889 100644 --- a/schedule_timers/c/schedule_timers_c.slsrc.html +++ b/schedule_timers/c/schedule_timers_c.slsrc.html @@ -18,61 +18,61 @@ diff --git a/seq_number_callback/c/seq_number_callback.c b/seq_number_callback/c/seq_number_callback.c index 89e54da..a93e28a 100644 --- a/seq_number_callback/c/seq_number_callback.c +++ b/seq_number_callback/c/seq_number_callback.c @@ -1,4 +1,23 @@ -/* seq_number_callback.c - http://ultramessaging.github.io/UMExamples */ +/* seq_number_callback.c - see http://ultramessaging.github.io/UMExamples/seq_number_callback/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 00036 00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 00058 00059 00060 @@ -81,10 +81,48 @@ 00063 00064 00065 -00066 -00067 +00066 +00067 00068 - /* Code Disclaimer? */ +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 + /* schedule_timers.c - see http://ultramessaging.github.io/UMExamples/schedule_timers/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -110,48 +148,48 @@ } \ } while (0) - int wait = 1; + int wait_flag = 1; - /* Timer callback function */ - int sample_timer_handler(lbm_context_t *ctx, const void *clientd) + + /* Timer callback function */ + int sample_timer_handler(lbm_context_t *ctx, const void *clientd) { printf("Timer executed. Set wait to 0 so application can cleanly exit\n"); - wait = 0; - } + wait_flag = 0; + + return 0; + } /* sample_timer_handler */ + - main() + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ - int timer_id; /* Used to get timer id from schedule API */ + lbm_context_t *ctx; /* Context object */ + int timer_id; /* Used to get timer id from schedule API */ + int err; /* Initialize context atrributes and create context */ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); - if ((timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000)) == -1) { - fprintf(stderr, "%s:%d, lbm error: '%s'\n", __FILE__, __LINE__, lbm_errmsg()); - exit(1); - } + /* Be careful! lbm_schedule_timer() returns >0 on success. */ + timer_id = lbm_schedule_timer(ctx, sample_timer_handler, NULL, NULL, 1000); + EX_LBM_CHK(timer_id); /* Now wait for callback to end the wait and close the application */ - while (wait) + while (wait_flag) SLEEP(1); /* Clean up */ err = lbm_context_delete(ctx); EX_LBM_CHK(err); - + #if defined(_MSC_VER) /* Windows-specific cleanup overhead */ WSACleanup(); #endif - } + return 0; + } /* main */ @@ -17,18 +36,17 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: { @@ -39,7 +57,7 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: - { + { lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", msg->topic_name, msg->source, reg->sequence_number, reg->flags); @@ -51,31 +69,35 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } return 0; -} +} /* rcv_handle_msg */ + int ume_rcv_seqnum_ex(lbm_ume_rcv_recovery_info_ex_func_info_t *info, void *clientd) { - printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n",info->low_sequence_number); + printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n", info->low_sequence_number); printf("info->high_sequence_number[%d] is the highest sequence number available in the persisted stores.\n", info->high_sequence_number); printf("info->low_rxreq_max_sequence_number[%d] is the lowest sequence number to be requested.\n", info->low_rxreq_max_sequence_number); - - /* Overwrite this variable to set a new starting sequence number. If the message is available in the store, then the receiver will - retransmission starting at this sequence number leading up to the high sequence number. If the new starting sequence number has - yet to be published, the receiver will discard new messages until this sequence number is sent */ + + /* Overwrite this variable to set a new starting sequence number. + * If the message is available in the store, then the receiver will + * retransmission starting at this sequence number leading up to the + * high sequence number. If the new starting sequence number has + * yet to be published, the receiver will discard new messages until + * this sequence number is sent */ info->low_sequence_number = 100; return 0; -} +} /* ume_rcv_seqnum_ex */ + -main() +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ lbm_ume_rcv_recovery_info_ex_func_t cb; /* Sequence number info callback function */ - int err; /* Used for checking API return codes */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -102,7 +124,7 @@ main() EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -119,4 +141,5 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif -} /* main */ + return 0; +} /* main */ diff --git a/seq_number_callback/c/seq_number_callback.sldoc.html b/seq_number_callback/c/seq_number_callback.sldoc.html index 3fa6fa8..d59108d 100644 --- a/seq_number_callback/c/seq_number_callback.sldoc.html +++ b/seq_number_callback/c/seq_number_callback.sldoc.html @@ -66,8 +66,8 @@ Context Create
Standard context creation.
-00092 err = lbm_context_create(&ctx, NULL, NULL, NULL); -00093 EX_LBM_CHK(err); +00114 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00115 EX_LBM_CHK(err);@@ -75,7 +75,7 @@Set Sequence Number Callback Attrribute
Setting the sequence number info callback requires a callback object to be defined:
-00077 lbm_ume_rcv_recovery_info_ex_func_t cb; /* Sequence number info callback function */ +00099 lbm_ume_rcv_recovery_info_ex_func_t cb; /* Sequence number info callback function */@@ -92,10 +92,10 @@Set Sequence Number Callback Attrribute
like so:-00099 cb.func = ume_rcv_seqnum_ex; -00100 cb.clientd = NULL; -00101 err = lbm_rcv_topic_attr_setopt(rattr, "ume_recovery_sequence_number_info_function", &cb, sizeof(cb)); -00102 EX_LBM_CHK(err); +00121 cb.func = ume_rcv_seqnum_ex; +00122 cb.clientd = NULL; +00123 err = lbm_rcv_topic_attr_setopt(rattr, "ume_recovery_sequence_number_info_function", &cb, sizeof(cb)); +00124 EX_LBM_CHK(err);@@ -107,19 +107,22 @@The Sequence Number Callback
receiver is starting at the correct sequence number.-00056 int ume_rcv_seqnum_ex(lbm_ume_rcv_recovery_info_ex_func_info_t *info, void *clientd) -00057 { -00058 printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n",info->low_sequence_number); -00059 printf("info->high_sequence_number[%d] is the highest sequence number available in the persisted stores.\n", info->high_sequence_number); -00060 printf("info->low_rxreq_max_sequence_number[%d] is the lowest sequence number to be requested.\n", info->low_rxreq_max_sequence_number); -00061 -00062 /* Overwrite this variable to set a new starting sequence number. If the message is available in the store, then the receiver will -00063 retransmission starting at this sequence number leading up to the high sequence number. If the new starting sequence number has -00064 yet to be published, the receiver will discard new messages until this sequence number is sent */ -00065 info->low_sequence_number = 100; -00066 -00067 return 0; -00068 } +00075 int ume_rcv_seqnum_ex(lbm_ume_rcv_recovery_info_ex_func_info_t *info, void *clientd) +00076 { +00077 printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n", info->low_sequence_number); +00078 printf("info->high_sequence_number[%d] is the highest sequence number available in the persisted stores.\n", info->high_sequence_number); +00079 printf("info->low_rxreq_max_sequence_number[%d] is the lowest sequence number to be requested.\n", info->low_rxreq_max_sequence_number); +00080 +00081 /* Overwrite this variable to set a new starting sequence number. +00082 * If the message is available in the store, then the receiver will +00083 * retransmission starting at this sequence number leading up to the +00084 * high sequence number. If the new starting sequence number has +00085 * yet to be published, the receiver will discard new messages until +00086 * this sequence number is sent */ +00087 info->low_sequence_number = 100; +00088 +00089 return 0; +00090 } /* ume_rcv_seqnum_ex */@@ -136,33 +139,32 @@Handle Message Callback
for debugging any kind of issues with related to message recovery, connectivity issues, and even performance.-00028 int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) -00029 { -00030 int err; -00031 -00032 switch (msg->type) { -00033 case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: -00034 { -00035 lbm_msg_ume_registration_ex_t *reg = (lbm_msg_ume_registration_ex_t *)(msg->data); -00036 printf("[%s][%s] store %u: %s UME registration successful. Sequence Number is %d.\n", -00037 msg->topic_name, msg->source, reg->store_index, reg->store,reg->sequence_number); -00038 -00039 break; -00040 } -00041 case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: -00042 { -00043 lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); -00044 printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", -00045 msg->topic_name, msg->source, reg->sequence_number, reg->flags); -00046 break; -00047 } -00048 default: -00049 printf("Other event, type=%x\n", msg->type); -00050 break; -00051 } -00052 -00053 return 0; -00054 } +00047 /* Callback used to handle request message for receiver */ +00048 int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +00049 { +00050 switch (msg->type) { +00051 case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: +00052 { +00053 lbm_msg_ume_registration_ex_t *reg = (lbm_msg_ume_registration_ex_t *)(msg->data); +00054 printf("[%s][%s] store %u: %s UME registration successful. Sequence Number is %d.\n", +00055 msg->topic_name, msg->source, reg->store_index, reg->store,reg->sequence_number); +00056 +00057 break; +00058 } +00059 case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: +00060 { +00061 lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); +00062 printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", +00063 msg->topic_name, msg->source, reg->sequence_number, reg->flags); +00064 break; +00065 } +00066 default: +00067 printf("Other event, type=%x\n", msg->type); +00068 break; +00069 } +00070 +00071 return 0; +00072 } /* rcv_handle_msg */@@ -171,20 +173,20 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>@@ -192,16 +194,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00080 #if defined(_WIN32) -00081 /* windows-specific code */ -00082 WSADATA wsadata; -00083 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00084 if (wsStat != 0) -00085 { -00086 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00087 exit(1); -00088 } -00089 #endif +00102 #if defined(_WIN32) +00103 /* windows-specific code */ +00104 WSADATA wsadata; +00105 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00106 if (wsStat != 0) +00107 { +00108 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00109 exit(1); +00110 } +00111 #endifdiff --git a/seq_number_callback/c/seq_number_callback_c.slsrc b/seq_number_callback/c/seq_number_callback_c.slsrc index 9d260bb..8d308ee 100644 --- a/seq_number_callback/c/seq_number_callback_c.slsrc +++ b/seq_number_callback/c/seq_number_callback_c.slsrc @@ -1,4 +1,23 @@ -/* seq_number_callback.c - http://ultramessaging.github.io/UMExamples */ +/* seq_number_callback.c - see http://ultramessaging.github.io/UMExamples/seq_number_callback/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -19,19 +38,18 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) -/* Callback used to handle request message for receiver */ + /* =semlit,block,handle_msg=*/ +/* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: { @@ -42,7 +60,7 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: - { + { lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", msg->topic_name, msg->source, reg->sequence_number, reg->flags); @@ -54,36 +72,40 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } return 0; -} +} /* rcv_handle_msg */ /* =semlit,endblock,handle_msg=*/ + /* =semlit,block,cb=*/ int ume_rcv_seqnum_ex(lbm_ume_rcv_recovery_info_ex_func_info_t *info, void *clientd) { - printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n",info->low_sequence_number); + printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n", info->low_sequence_number); printf("info->high_sequence_number[%d] is the highest sequence number available in the persisted stores.\n", info->high_sequence_number); printf("info->low_rxreq_max_sequence_number[%d] is the lowest sequence number to be requested.\n", info->low_rxreq_max_sequence_number); - - /* Overwrite this variable to set a new starting sequence number. If the message is available in the store, then the receiver will - retransmission starting at this sequence number leading up to the high sequence number. If the new starting sequence number has - yet to be published, the receiver will discard new messages until this sequence number is sent */ + + /* Overwrite this variable to set a new starting sequence number. + * If the message is available in the store, then the receiver will + * retransmission starting at this sequence number leading up to the + * high sequence number. If the new starting sequence number has + * yet to be published, the receiver will discard new messages until + * this sequence number is sent */ info->low_sequence_number = 100; return 0; -} +} /* ume_rcv_seqnum_ex */ /* =semlit,endblock,cb=*/ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ /* =semlit,block,cb_var=*/ lbm_ume_rcv_recovery_info_ex_func_t cb; /* Sequence number info callback function */ /* =semlit,endblock,cb_var=*/ - int err; /* Used for checking API return codes */ + int err; /* =semlit,block,windows=*/ #if defined(_WIN32) @@ -116,7 +138,7 @@ main() /* =semlit,endblock,cb_attr=*/ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -133,4 +155,5 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif -} /* main */ + return 0; +} /* main */ diff --git a/seq_number_callback/c/seq_number_callback_c.slsrc.html b/seq_number_callback/c/seq_number_callback_c.slsrc.html index cac76ec..f784654 100644 --- a/seq_number_callback/c/seq_number_callback_c.slsrc.html +++ b/seq_number_callback/c/seq_number_callback_c.slsrc.html @@ -18,50 +18,50 @@ diff --git a/sequential_mode/c/sequential_mode.c b/sequential_mode/c/sequential_mode.c index 61c6d4a..0fd880c 100644 --- a/sequential_mode/c/sequential_mode.c +++ b/sequential_mode/c/sequential_mode.c @@ -1,6 +1,26 @@ -/* Code Disclaimer? */ +/* sequential_mode.c - see http://ultramessaging.github.io/UMExamples/sequential_mode/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 00047 00048 00049 @@ -70,75 +70,117 @@ 00052 00053 00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 00073 00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 00091 -00092 -00093 +00092 +00093 00094 00095 00096 00097 00098 -00099 -00100 -00101 -00102 -00103 -00104 -00105 -00106 -00107 -00108 -00109 -00110 -00111 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 00112 00113 -00114 -00115 +00114 +00115 00116 00117 00118 00119 00120 -00121 -00122 - /* seq_number_callback.c - http://ultramessaging.github.io/UMExamples */ +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 + /* seq_number_callback.c - see http://ultramessaging.github.io/UMExamples/seq_number_callback/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -157,18 +199,17 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) - /* Callback used to handle request message for receiver */ - int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) - { - int err; + /* Callback used to handle request message for receiver */ + int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) + { switch (msg->type) { case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: { @@ -179,7 +220,7 @@ break; } case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: - { + { lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", msg->topic_name, msg->source, reg->sequence_number, reg->flags); @@ -191,31 +232,35 @@ } return 0; - } + } /* rcv_handle_msg */ + int ume_rcv_seqnum_ex(lbm_ume_rcv_recovery_info_ex_func_info_t *info, void *clientd) { - printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n",info->low_sequence_number); + printf("info->low_sequence_number[%d] is the starting sequence number as determined by registration consensus.\n", info->low_sequence_number); printf("info->high_sequence_number[%d] is the highest sequence number available in the persisted stores.\n", info->high_sequence_number); printf("info->low_rxreq_max_sequence_number[%d] is the lowest sequence number to be requested.\n", info->low_rxreq_max_sequence_number); - - /* Overwrite this variable to set a new starting sequence number. If the message is available in the store, then the receiver will - retransmission starting at this sequence number leading up to the high sequence number. If the new starting sequence number has - yet to be published, the receiver will discard new messages until this sequence number is sent */ + + /* Overwrite this variable to set a new starting sequence number. + * If the message is available in the store, then the receiver will + * retransmission starting at this sequence number leading up to the + * high sequence number. If the new starting sequence number has + * yet to be published, the receiver will discard new messages until + * this sequence number is sent */ info->low_sequence_number = 100; return 0; - } + } /* ume_rcv_seqnum_ex */ + - main() + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ lbm_ume_rcv_recovery_info_ex_func_t cb; /* Sequence number info callback function */ - int err; /* Used for checking API return codes */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -242,7 +287,7 @@ EX_LBM_CHK(err); err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); @@ -259,7 +304,8 @@ /* Windows-specific cleanup overhead */ WSACleanup(); #endif - } /* main */ + return 0; + } /* main */ +#include #if defined(_MSC_VER) /* Windows-only includes */ @@ -15,6 +35,15 @@ #include +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + #if defined(_WIN32) DWORD WINAPI seq_thread(void *arg) @@ -23,59 +52,47 @@ void *seq_thread(void *arg) #endif /* _WIN32 */ { lbm_context_t *ctx = (lbm_context_t *) arg; + int err; while (1) { - if (lbm_context_process_events(ctx, 500) == -1) - { - printf("ERROR processing context events: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_context_process_events(ctx, 500); + EX_LBM_CHK(err); } -} +} /* seq_thread */ + -main() +int main(int argc, char **argv) { 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) */ + int err; #if defined(_WIN32) - HANDLE wthrdh; + HANDLE wthrdh; #else - pthread_t pthids; + 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) + /* windows-specific code */ + WSADATA wsadata; + int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); + if (wsStat != 0) { - fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); + printf("line %d: wsStat=%d\n",__LINE__,wsStat); exit(1); } +#endif + + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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_attr_str_setopt(cattr, "operational_mode", "sequential"); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, cattr, NULL, NULL); + EX_LBM_CHK(err); #if defined(_WIN32) if ((wthrdh = CreateThread(NULL, 0, seq_thread, ctx, 0, NULL)) == NULL) { @@ -89,7 +106,8 @@ main() } #endif /* _WIN32 */ - /* Wait forever */ + /* Wait forever (or until control-c). */ while (1) { } -} + return 0; +} /* main */ diff --git a/sequential_mode/c/sequential_mode.sldoc.html b/sequential_mode/c/sequential_mode.sldoc.html index 11d8657..f6a780c 100644 --- a/sequential_mode/c/sequential_mode.sldoc.html +++ b/sequential_mode/c/sequential_mode.sldoc.html @@ -53,25 +53,15 @@ Initialize and Create Context
Setting the operational_mode is required to take advantage of the sequential mode of operation.-00060 if (lbm_context_attr_create(&cattr) != 0) -00061 { -00062 fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); -00063 exit(1); -00064 } -00065 -00066 /* Setting the resolver address using the string method */ -00067 if (lbm_context_attr_str_setopt(cattr, "operational_mode", "sequential") != 0) -00068 { -00069 fprintf(stderr, "lbm_context_attr_str_setopt:operational_mode: %s\n", lbm_errmsg()); -00070 exit(1); -00071 } -00072 -00073 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00074 if (err) -00075 { -00076 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00077 exit(1); -00078 } +00087 err = lbm_context_attr_create(&cattr); +00088 EX_LBM_CHK(err); +00089 +00090 /* Setting the resolver address using the string method */ +00091 err = lbm_context_attr_str_setopt(cattr, "operational_mode", "sequential"); +00092 EX_LBM_CHK(err); +00093 +00094 err = lbm_context_create(&ctx, cattr, NULL, NULL); +00095 EX_LBM_CHK(err);@@ -81,17 +71,17 @@Spawn a New Thread
for message delivery. Notice the thread function is "seq_thread", which will be explained in the next block.-00080 #if defined(_WIN32) -00081 if ((wthrdh = CreateThread(NULL, 0, seq_thread, ctx, 0, NULL)) == NULL) { -00082 fprintf(stderr, "could not create thread\n"); -00083 exit(1); -00084 } -00085 #else -00086 if (pthread_create(&pthids, NULL, seq_thread, ctx) != 0) { -00087 fprintf(stderr, "could not spawn thread\n"); -00088 exit(1); -00089 } -00090 #endif /* _WIN32 */ +00097 #if defined(_WIN32) +00098 if ((wthrdh = CreateThread(NULL, 0, seq_thread, ctx, 0, NULL)) == NULL) { +00099 fprintf(stderr, "could not create thread\n"); +00100 exit(1); +00101 } +00102 #else +00103 if (pthread_create(&pthids, NULL, seq_thread, ctx) != 0) { +00104 fprintf(stderr, "could not spawn thread\n"); +00105 exit(1); +00106 } +00107 #endif /* _WIN32 */@@ -100,23 +90,21 @@Sequential Context Thread
calls the process events API, ensures there are no errors, and repeats.-00019 #if defined(_WIN32) -00020 DWORD WINAPI seq_thread(void *arg) -00021 #else -00022 void *seq_thread(void *arg) -00023 #endif /* _WIN32 */ -00024 { -00025 lbm_context_t *ctx = (lbm_context_t *) arg; -00026 -00027 while (1) -00028 { -00029 if (lbm_context_process_events(ctx, 500) == -1) -00030 { -00031 printf("ERROR processing context events: %s\n", lbm_errmsg()); -00032 exit(1); -00033 } -00034 } -00035 } +00048 #if defined(_WIN32) +00049 DWORD WINAPI seq_thread(void *arg) +00050 #else +00051 void *seq_thread(void *arg) +00052 #endif /* _WIN32 */ +00053 { +00054 lbm_context_t *ctx = (lbm_context_t *) arg; +00055 int err; +00056 +00057 while (1) +00058 { +00059 err = lbm_context_process_events(ctx, 500); +00060 EX_LBM_CHK(err); +00061 } +00062 } /* seq_thread */@@ -125,20 +113,21 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 #include <pthread.h> +00024 +00025 #if defined(_MSC_VER) +00026 /* Windows-only includes */ +00027 #include <winsock2.h> +00028 #define SLEEP(s) Sleep((s)*1000) +00029 #else +00030 /* Unix-only includes */ +00031 #include <stdlib.h> +00032 #include <unistd.h> +00033 #define SLEEP(s) sleep(s) +00034 #endif +00035 +00036 #include <lbm/lbm.h>@@ -146,16 +135,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00049 #if defined(_MSC_VER) -00050 /* windows-specific code */ -00051 WSADATA wsadata; -00052 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00053 if (wsStat != 0) -00054 { -00055 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00056 exit(1); -00057 } -00058 #endif +00076 #if defined(_MSC_VER) +00077 /* windows-specific code */ +00078 WSADATA wsadata; +00079 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00080 if (wsStat != 0) +00081 { +00082 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00083 exit(1); +00084 } +00085 #endifdiff --git a/sequential_mode/c/sequential_mode_c.slsrc b/sequential_mode/c/sequential_mode_c.slsrc index 1505185..91b3c95 100644 --- a/sequential_mode/c/sequential_mode_c.slsrc +++ b/sequential_mode/c/sequential_mode_c.slsrc @@ -1,7 +1,27 @@ -/* Code Disclaimer? */ +/* sequential_mode.c - see http://ultramessaging.github.io/UMExamples/sequential_mode/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include+#include #if defined(_MSC_VER) /* Windows-only includes */ @@ -17,6 +37,15 @@ #include /* =semlit,endblock,includes=*/ +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + /* =semlit,block,context_thread=*/ #if defined(_WIN32) @@ -26,64 +55,52 @@ void *seq_thread(void *arg) #endif /* _WIN32 */ { lbm_context_t *ctx = (lbm_context_t *) arg; + int err; while (1) { - if (lbm_context_process_events(ctx, 500) == -1) - { - printf("ERROR processing context events: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_context_process_events(ctx, 500); + EX_LBM_CHK(err); } -} +} /* seq_thread */ /* =semlit,endblock,context_thread=*/ -main() + +int main(int argc, char **argv) { 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) */ + int err; #if defined(_WIN32) - HANDLE wthrdh; + HANDLE wthrdh; #else - pthread_t pthids; + pthread_t pthids; #endif /* _WIN32 */ - - /* =semlit,block,windows=*/ + /* =semlit,block,windows=*/ #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 - /* =semlit,endblock,windows=*/ - - /* =semlit,block,create= */ - if (lbm_context_attr_create(&cattr) != 0) + /* windows-specific code */ + WSADATA wsadata; + int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); + if (wsStat != 0) { - fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); + printf("line %d: wsStat=%d\n",__LINE__,wsStat); exit(1); } +#endif + /* =semlit,endblock,windows=*/ + + /* =semlit,block,create= */ + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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_attr_str_setopt(cattr, "operational_mode", "sequential"); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - /* =semlit,endblock,create=*/ + err = lbm_context_create(&ctx, cattr, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,create=*/ /* =semlit,block,spawn_thread=*/ #if defined(_WIN32) @@ -99,7 +116,8 @@ main() #endif /* _WIN32 */ /* =semlit,endblock,spawn_thread=*/ - /* Wait forever */ + /* Wait forever (or until control-c). */ while (1) { } -} + return 0; +} /* main */ diff --git a/sequential_mode/c/sequential_mode_c.slsrc.html b/sequential_mode/c/sequential_mode_c.slsrc.html index d712b4f..7418105 100644 --- a/sequential_mode/c/sequential_mode_c.slsrc.html +++ b/sequential_mode/c/sequential_mode_c.slsrc.html @@ -18,40 +18,40 @@ diff --git a/setting_attributes/c/setting_attributes.c b/setting_attributes/c/setting_attributes.c index fd49ccc..2793c4f 100644 --- a/setting_attributes/c/setting_attributes.c +++ b/setting_attributes/c/setting_attributes.c @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* setting_attributes.c - see http://ultramessaging.github.io/UMExamples/setting_attributes/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 00037 00038 00039 @@ -63,57 +63,95 @@ 00045 00046 00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 - /* Code Disclaimer? */ +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 + /* sequential_mode.c - see http://ultramessaging.github.io/UMExamples/sequential_mode/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> + #include <pthread.h> #if defined(_MSC_VER) /* Windows-only includes */ @@ -128,6 +166,15 @@ #include <lbm/lbm.h> + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + #if defined(_WIN32) DWORD WINAPI seq_thread(void *arg) @@ -136,59 +183,47 @@ #endif /* _WIN32 */ { lbm_context_t *ctx = (lbm_context_t *) arg; + int err; while (1) { - if (lbm_context_process_events(ctx, 500) == -1) - { - printf("ERROR processing context events: %s\n", lbm_errmsg()); - exit(1); - } + err = lbm_context_process_events(ctx, 500); + EX_LBM_CHK(err); } - } + } /* seq_thread */ + - main() + int main(int argc, char **argv) { 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) */ + int err; #if defined(_WIN32) - HANDLE wthrdh; + HANDLE wthrdh; #else - pthread_t pthids; + 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) + /* windows-specific code */ + WSADATA wsadata; + int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); + if (wsStat != 0) { - fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); + printf("line %d: wsStat=%d\n",__LINE__,wsStat); exit(1); } + #endif + + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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_attr_str_setopt(cattr, "operational_mode", "sequential"); + EX_LBM_CHK(err); - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + err = lbm_context_create(&ctx, cattr, NULL, NULL); + EX_LBM_CHK(err); #if defined(_WIN32) if ((wthrdh = CreateThread(NULL, 0, seq_thread, ctx, 0, NULL)) == NULL) { @@ -202,10 +237,11 @@ } #endif /* _WIN32 */ - /* Wait forever */ + /* Wait forever (or until control-c). */ while (1) { } - } + return 0; + } /* main */ @@ -15,144 +34,116 @@ #include -main() +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + +int main(int argc, char **argv) { - 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) */ + 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; #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); - } + /* 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); + /* Initialize the defaults for the context attribute object */ + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); + + /* Setting the resolver address using the string method */ + err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); + EX_LBM_CHK(err); + + /* Setting the resolver port using the data-type value method */ + res_port = 12345; + err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); + + /* Creating the context */ + err = lbm_context_create(&ctx, cattr, NULL, NULL); + EX_LBM_CHK(err); + + /* Delete the context attribute object */ + err = lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); + + /* Initializing the source attribute object */ + err = lbm_src_topic_attr_create(&tattr_1); + + /* Setting the transport via the source topic string method */ + err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); + EX_LBM_CHK(err); + + /* Setting the lbtrm destination port via the direct value set method */ + des_port = 14001; + err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); + + /* Allocating the topic */ + err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); + EX_LBM_CHK(err); + + /* Creating the source */ + err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); + EX_LBM_CHK(err); + + /* Initialized the second source attributes as a copy of the first */ + err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); + EX_LBM_CHK(err); + + /* Now modify the destination port for this second source to put the + * publisher on a different transport. */ + des_port = 14002; + err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); + + /* Allocating the second topic */ + err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); + EX_LBM_CHK(err); + + /* Creating the source */ + err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); + EX_LBM_CHK(err); + + /* Delete the first and second source topic attribute objects */ + err = lbm_src_topic_attr_delete(tattr_1); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_delete(tattr_2); + EX_LBM_CHK(err); + + /* Finished with all LBM functions, delete the source and context object. */ + err = lbm_src_delete(src_1); + EX_LBM_CHK(err); + err = lbm_src_delete(src_2); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - WSACleanup(); + WSACleanup(); #endif -} - + return 0; +} /* main */ diff --git a/setting_attributes/c/setting_attributes.sldoc.html b/setting_attributes/c/setting_attributes.sldoc.html index 55fd4ee..ec96d80 100644 --- a/setting_attributes/c/setting_attributes.sldoc.html +++ b/setting_attributes/c/setting_attributes.sldoc.html @@ -25,8 +25,8 @@ Source Topic Attribute Pointer
two variables are declared.-00025 lbm_src_topic_attr_t *tattr_1; /* pointer to source attribute object */ -00026 lbm_src_topic_attr_t *tattr_2; /* pointer to source attribute object */ +00054 lbm_src_topic_attr_t *tattr_1; /* pointer to source attribute object */ +00055 lbm_src_topic_attr_t *tattr_2; /* pointer to source attribute object */@@ -34,7 +34,7 @@Context Attribute declatation
This is the declaration for the context attribute.
-00027 lbm_context_attr_t * cattr; /* pointer to context attribute object */ +00056 lbm_context_attr_t * cattr; /* pointer to context attribute object */@@ -42,8 +42,8 @@Attribute Variables
Declaring these two variables to be used while setting the topic resolution port and LBTRM destination port
-00028 lbm_uint16_t res_port; /* Int to set resolver port */ -00029 lbm_uint16_t des_port; /* Int to set lbtrm destination port */ +00057 lbm_uint16_t res_port; /* Int to set resolver port */ +00058 lbm_uint16_t des_port; /* Int to set lbtrm destination port */@@ -53,12 +53,9 @@Initialize Context Attributes
is created.-00043 /* Initialize the defaults for the context attribute object */ -00044 if (lbm_context_attr_create(&cattr) != 0) -00045 { -00046 fprintf(stderr, "lbm_context_attr_create: %s\n", lbm_errmsg()); -00047 exit(1); -00048 } +00072 /* Initialize the defaults for the context attribute object */ +00073 err = lbm_context_attr_create(&cattr); +00074 EX_LBM_CHK(err);@@ -76,12 +73,9 @@Setting Context Attribute using the String Method
which configures this applications topic resolution multicast address using the string method.-00050 /* Setting the resolver address using the string method */ -00051 if (lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12") != 0) -00052 { -00053 fprintf(stderr, "lbm_context_attr_str_setopt:resolver_multicast_address: %s\n", lbm_errmsg()); -00054 exit(1); -00055 } +00076 /* Setting the resolver address using the string method */ +00077 err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); +00078 EX_LBM_CHK(err);@@ -99,13 +93,10 @@Setting Context Attributes using the Data Type Method
defined previously will use.-00057 /* Setting the resolver port using the data-type value method */ -00058 res_port = 12345; -00059 if (lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)) != 0 ) -00060 { -00061 fprintf(stderr, "lbm_context_attr_setopt:resolver_mutlicast_port: %s\n", lbm_errmsg()); -00062 exit(1); -00063 } +00080 /* Setting the resolver port using the data-type value method */ +00081 res_port = 12345; +00082 err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); +00083 EX_LBM_CHK(err);@@ -113,13 +104,9 @@Create the Context Using the Attributes
Now create the context using the attributes that were just previously configured. Notice the attributes object as the second parameter
-00065 /* Creating the context */ -00066 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00067 if (err) -00068 { -00069 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00070 exit(1); -00071 } +00085 /* Creating the context */ +00086 err = lbm_context_create(&ctx, cattr, NULL, NULL); +00087 EX_LBM_CHK(err);@@ -127,8 +114,9 @@Delete the Attribute Object
Delete the attribute object to clean up
-00073 /* Delete the context attribute object */ -00074 lbm_context_attr_delete(cattr); +00089 /* Delete the context attribute object */ +00090 err = lbm_context_attr_delete(cattr); +00091 EX_LBM_CHK(err);@@ -136,12 +124,8 @@Initialize Source Attribute for test.topic.1
Like the context attribute object, the source topic attribute object must also be initialized
-00076 /* Initializing the source attribute object */ -00077 if (lbm_src_topic_attr_create(&tattr_1) != 0) -00078 { -00079 fprintf(stderr, "lbm_src_topic_attr_create: %s\n", lbm_errmsg()); -00080 exit(1); -00081 } +00093 /* Initializing the source attribute object */ +00094 err = lbm_src_topic_attr_create(&tattr_1);@@ -163,12 +147,9 @@Setting Source Attribute via String
-00083 /* Setting the transport via the source topic string method */ -00084 if (lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm") != 0 ) -00085 { -00086 fprintf(stderr, "lbm_src_topic_attr_str_setopt:transport: %s\n", lbm_errmsg()); -00087 exit(1); -00088 } +00096 /* Setting the transport via the source topic string method */ +00097 err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); +00098 EX_LBM_CHK(err);@@ -185,13 +166,10 @@Setting Source Attribute via Data Type
-00090 /* Setting the lbtrm destination port via the direct value set method */ -00091 des_port = 14001; -00092 if (lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)) != 0 ) -00093 { -00094 fprintf(stderr, "lbm_src_topic_attr_setopt:transport_lbtrm_destination_port: %s\n", lbm_errmsg()); -00095 exit(1); -00096 } +00100 /* Setting the lbtrm destination port via the direct value set method */ +00101 des_port = 14001; +00102 err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); +00103 EX_LBM_CHK(err);@@ -199,13 +177,9 @@Allocate the Topic for test.topic.1
Allocate the topic for the first publisher
-00098 /* Allocating the topic */ -00099 err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); -00100 if (err) -00101 { -00102 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00103 exit(1); -00104 } +00105 /* Allocating the topic */ +00106 err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); +00107 EX_LBM_CHK(err);@@ -213,13 +187,9 @@Create the First Source
Create the source test.topic.1 by calling lbm_src_create(), and passing the attribute object in as the third paramter
-00106 /* Creating the source */ -00107 err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); -00108 if (err) -00109 { -00110 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00111 exit(1); -00112 } +00109 /* Creating the source */ +00110 err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); +00111 EX_LBM_CHK(err);@@ -228,12 +198,9 @@Clone Attribues for Second Source
second attribute object. After the copy, alterations can be made prior to the creation of the second source-00114 /* Initialized the second source attributes as a copy of the first */ -00115 if (lbm_src_topic_attr_dup(&tattr_2, tattr_1) != 0 ) -00116 { -00117 fprintf(stderr, "lbm_src_topic_attr_dup: %s\n", lbm_errmsg()); -00118 exit(1); -00119 } +00113 /* Initialized the second source attributes as a copy of the first */ +00114 err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); +00115 EX_LBM_CHK(err);@@ -254,13 +221,11 @@Change the Multicast Port
-00121 /* Now modify the destination port for this second source to put the publisher on a different transport */ -00122 des_port = 14002; -00123 if (lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)) != 0 ) -00124 { -00125 fprintf(stderr, "lbm_src_topic_attr_setopt:transport_lbtrm_destination_port: %s\n", lbm_errmsg()); -00126 exit(1); -00127 } +00117 /* Now modify the destination port for this second source to put the +00118 * publisher on a different transport. */ +00119 des_port = 14002; +00120 err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); +00121 EX_LBM_CHK(err);@@ -268,21 +233,13 @@Allocate and Create test.topic.2
Just like previously done for the first publisher, allocate the topic with the configured attributes and create the source
-00129 /* Allocating the second topic */ -00130 err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); -00131 if (err) -00132 { -00133 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00134 exit(1); -00135 } -00136 -00137 /* Creating the source */ -00138 err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); -00139 if (err) -00140 { -00141 printf("line %d: %s\n", __LINE__, lbm_errmsg()); -00142 exit(1); -00143 } +00123 /* Allocating the second topic */ +00124 err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); +00125 EX_LBM_CHK(err); +00126 +00127 /* Creating the source */ +00128 err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); +00129 EX_LBM_CHK(err);@@ -290,9 +247,11 @@Delete the Source Attribute Objects
Deleting the source attribute objects is a good best practice
-00145 /* Delete the first and second source topic attribute objects */ -00146 lbm_src_topic_attr_delete(tattr_1); -00147 lbm_src_topic_attr_delete(tattr_2); +00131 /* Delete the first and second source topic attribute objects */ +00132 err = lbm_src_topic_attr_delete(tattr_1); +00133 EX_LBM_CHK(err); +00134 err = lbm_src_topic_attr_delete(tattr_2); +00135 EX_LBM_CHK(err);@@ -301,10 +260,13 @@Delete the Sources and Context
before deleting the context-00149 /* Finished with all LBM functions, delete the source and context object. */ -00150 lbm_src_delete(src_1); -00151 lbm_src_delete(src_2); -00152 lbm_context_delete(ctx); +00137 /* Finished with all LBM functions, delete the source and context object. */ +00138 err = lbm_src_delete(src_1); +00139 EX_LBM_CHK(err); +00140 err = lbm_src_delete(src_2); +00141 EX_LBM_CHK(err); +00142 err = lbm_context_delete(ctx); +00143 EX_LBM_CHK(err);@@ -312,20 +274,20 @@Includes
Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>diff --git a/setting_attributes/c/setting_attributes_c.slsrc b/setting_attributes/c/setting_attributes_c.slsrc index a65b612..001ff72 100644 --- a/setting_attributes/c/setting_attributes_c.slsrc +++ b/setting_attributes/c/setting_attributes_c.slsrc @@ -1,4 +1,23 @@ -/* Example on setting Ultra Messaging attributes */ +/* setting_attributes.c - see http://ultramessaging.github.io/UMExamples/setting_attributes/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -17,180 +36,152 @@ #include /* =semlit,endblock,includes=*/ -main() +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + +int main(int argc, char **argv) { - 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 */ - /* =semlit,block,topic_attr=*/ - lbm_src_topic_attr_t *tattr_1; /* pointer to source attribute object */ - lbm_src_topic_attr_t *tattr_2; /* pointer to source attribute object */ - /* =semlit,endblock,topic_attr=*/ - /* =semlit,block,ctx_attr=*/ - lbm_context_attr_t * cattr; /* pointer to context attribute object */ - /* =semlit,endblock,ctx_attr=*/ - /* =semlit,block,attr_settings=*/ - lbm_uint16_t res_port; /* Int to set resolver port */ - lbm_uint16_t des_port; /* Int to set lbtrm destination port */ - /* =semlit,endblock,attr_settings=*/ - int err; /* return status of lbm functions (true=error) */ + 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 */ + /* =semlit,block,topic_attr=*/ + lbm_src_topic_attr_t *tattr_1; /* pointer to source attribute object */ + lbm_src_topic_attr_t *tattr_2; /* pointer to source attribute object */ + /* =semlit,endblock,topic_attr=*/ + /* =semlit,block,ctx_attr=*/ + lbm_context_attr_t * cattr; /* pointer to context attribute object */ + /* =semlit,endblock,ctx_attr=*/ + /* =semlit,block,attr_settings=*/ + lbm_uint16_t res_port; /* Int to set resolver port */ + lbm_uint16_t des_port; /* Int to set lbtrm destination port */ + /* =semlit,endblock,attr_settings=*/ + int err; #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); - } + /* 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 - /* =semlit,block,init_ctx=*/ - /* 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); - } - /* =semlit,endblock,init_ctx=*/ - - /* =semlit,block,ctx_res_addr=*/ - /* 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); - } - /* =semlit,endblock,ctx_res_addr=*/ - - /* =semlit,block,ctx_res_port=*/ - /* 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); - } - /* =semlit,endblock,ctx_res_port=*/ - - /* =semlit,block,ctx_create=*/ - /* Creating the context */ - err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } - /* =semlit,endblock,ctx_create=*/ - - /* =semlit,block,ctx_attr_del=*/ - /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); - /* =semlit,endblock,ctx_attr_del=*/ - - /* =semlit,block,topic1_init=*/ - /* 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); - } - /* =semlit,endblock,topic1_init=*/ - - /* =semlit,block,topic1_transport=*/ - /* 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); - } - /* =semlit,endblock,topic1_transport=*/ - - /* =semlit,block,topic1_port=*/ - /* 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); - } - /* =semlit,endblock,topic1_port=*/ - - /* =semlit,block,topic1_alloc=*/ - /* 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); - } - /* =semlit,endblock,topic1_alloc=*/ - - /* =semlit,block,topic1_create=*/ - /* 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); - } - /* =semlit,endblock,topic1_create=*/ - - /* =semlit,block,topic2_clone=*/ - /* 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); - } - /* =semlit,endblock,topic2_clone=*/ - - /* =semlit,block,topic2_port=*/ - /* 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); - } - /* =semlit,endblock,topic2_port=*/ - - /* =semlit,block,topic2_create=*/ - /* 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); - } - /* =semlit,endblock,topic2_create=*/ - - /* =semlit,block,topic_attr_del=*/ - /* Delete the first and second source topic attribute objects */ - lbm_src_topic_attr_delete(tattr_1); - lbm_src_topic_attr_delete(tattr_2); - /* =semlit,endblock,topic_attr_del=*/ - - /* =semlit,block,clean=*/ - /* 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); - /* =semlit,endblock,clean=*/ + /* =semlit,block,init_ctx=*/ + /* Initialize the defaults for the context attribute object */ + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); + /* =semlit,endblock,init_ctx=*/ + + /* =semlit,block,ctx_res_addr=*/ + /* Setting the resolver address using the string method */ + err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); + EX_LBM_CHK(err); + /* =semlit,endblock,ctx_res_addr=*/ + + /* =semlit,block,ctx_res_port=*/ + /* Setting the resolver port using the data-type value method */ + res_port = 12345; + err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); + /* =semlit,endblock,ctx_res_port=*/ + + /* =semlit,block,ctx_create=*/ + /* Creating the context */ + err = lbm_context_create(&ctx, cattr, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,ctx_create=*/ + + /* =semlit,block,ctx_attr_del=*/ + /* Delete the context attribute object */ + err = lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); + /* =semlit,endblock,ctx_attr_del=*/ + + /* =semlit,block,topic1_init=*/ + /* Initializing the source attribute object */ + err = lbm_src_topic_attr_create(&tattr_1); + /* =semlit,endblock,topic1_init=*/ + + /* =semlit,block,topic1_transport=*/ + /* Setting the transport via the source topic string method */ + err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); + EX_LBM_CHK(err); + /* =semlit,endblock,topic1_transport=*/ + + /* =semlit,block,topic1_port=*/ + /* Setting the lbtrm destination port via the direct value set method */ + des_port = 14001; + err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); + /* =semlit,endblock,topic1_port=*/ + + /* =semlit,block,topic1_alloc=*/ + /* Allocating the topic */ + err = lbm_src_topic_alloc(&topic_1, ctx, "test.topic.1", tattr_1); + EX_LBM_CHK(err); + /* =semlit,endblock,topic1_alloc=*/ + + /* =semlit,block,topic1_create=*/ + /* Creating the source */ + err = lbm_src_create(&src_1, ctx, topic_1, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,topic1_create=*/ + + /* =semlit,block,topic2_clone=*/ + /* Initialized the second source attributes as a copy of the first */ + err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); + EX_LBM_CHK(err); + /* =semlit,endblock,topic2_clone=*/ + + /* =semlit,block,topic2_port=*/ + /* Now modify the destination port for this second source to put the + * publisher on a different transport. */ + des_port = 14002; + err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); + /* =semlit,endblock,topic2_port=*/ + + /* =semlit,block,topic2_create=*/ + /* Allocating the second topic */ + err = lbm_src_topic_alloc(&topic_2, ctx, "test.topic.2", tattr_2); + EX_LBM_CHK(err); + + /* Creating the source */ + err = lbm_src_create(&src_2, ctx, topic_2, NULL, NULL, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,topic2_create=*/ + + /* =semlit,block,topic_attr_del=*/ + /* Delete the first and second source topic attribute objects */ + err = lbm_src_topic_attr_delete(tattr_1); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_delete(tattr_2); + EX_LBM_CHK(err); + /* =semlit,endblock,topic_attr_del=*/ + + /* =semlit,block,clean=*/ + /* Finished with all LBM functions, delete the source and context object. */ + err = lbm_src_delete(src_1); + EX_LBM_CHK(err); + err = lbm_src_delete(src_2); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + /* =semlit,endblock,clean=*/ #if defined(_MSC_VER) - WSACleanup(); + WSACleanup(); #endif -} - + return 0; +} /* main */ diff --git a/setting_attributes/c/setting_attributes_c.slsrc.html b/setting_attributes/c/setting_attributes_c.slsrc.html index cf31618..6c519a8 100644 --- a/setting_attributes/c/setting_attributes_c.slsrc.html +++ b/setting_attributes/c/setting_attributes_c.slsrc.html @@ -18,39 +18,39 @@ diff --git a/source_create/c/source_create_c.slsrc b/source_create/c/source_create_c.slsrc index 03ef0ad..60bb422 100644 --- a/source_create/c/source_create_c.slsrc +++ b/source_create/c/source_create_c.slsrc @@ -17,7 +17,7 @@ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 00036 00037 00038 @@ -58,123 +58,133 @@ 00040 00041 00042 -00043 -00044 -00045 -00046 -00047 -00048 +00043 +00044 +00045 +00046 +00047 +00048 00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 -00099 -00100 -00101 -00102 -00103 -00104 -00105 -00106 -00107 -00108 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 00109 00110 00111 -00112 -00113 +00112 +00113 00114 00115 -00116 -00117 -00118 -00119 -00120 +00116 +00117 +00118 +00119 +00120 00121 -00122 -00123 -00124 -00125 -00126 -00127 -00128 +00122 +00123 +00124 +00125 +00126 +00127 +00128 00129 -00130 -00131 -00132 -00133 -00134 -00135 -00136 -00137 -00138 -00139 -00140 -00141 -00142 -00143 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 00144 -00145 -00146 -00147 +00145 +00146 +00147 00148 -00149 -00150 -00151 -00152 -00153 -00154 -00155 -00156 -00157 -00158 - /* Example on setting Ultra Messaging attributes */ +00149 + /* setting_attributes.c - see http://ultramessaging.github.io/UMExamples/setting_attributes/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -191,7 +201,17 @@ #include <lbm/lbm.h> - main() + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + + int main(int argc, char **argv) { lbm_context_t *ctx; /* pointer to context object */ lbm_topic_t *topic_1; /* pointer to topic object */ @@ -203,7 +223,7 @@ 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) */ + int err; #if defined(_MSC_VER) /* windows-specific code */ @@ -217,121 +237,83 @@ #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); - } + err = lbm_context_attr_create(&cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_str_setopt(cattr, "resolver_multicast_address", "224.10.11.12"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_context_attr_setopt(cattr, "resolver_multicast_port", &res_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* Creating the context */ err = lbm_context_create(&ctx, cattr, NULL, NULL); - if (err) - { - printf("line %d: %s\n", __LINE__, lbm_errmsg()); - exit(1); - } + EX_LBM_CHK(err); /* Delete the context attribute object */ - lbm_context_attr_delete(cattr); + err = lbm_context_attr_delete(cattr); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_create(&tattr_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); - } + err = lbm_src_topic_attr_str_setopt(tattr_1, "transport", "lbtrm"); + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_1, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + err = lbm_src_topic_attr_dup(&tattr_2, tattr_1); + EX_LBM_CHK(err); - /* Now modify the destination port for this second source to put the publisher on a different transport */ + /* 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); - } + err = lbm_src_topic_attr_setopt(tattr_2, "transport_lbtrm_destination_port", &des_port, sizeof(lbm_uint16_t)); + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* 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); - } + EX_LBM_CHK(err); /* Delete the first and second source topic attribute objects */ - lbm_src_topic_attr_delete(tattr_1); - lbm_src_topic_attr_delete(tattr_2); + err = lbm_src_topic_attr_delete(tattr_1); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_delete(tattr_2); + EX_LBM_CHK(err); /* 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); + err = lbm_src_delete(src_1); + EX_LBM_CHK(err); + err = lbm_src_delete(src_2); + EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif - } - + return 0; + } /* main */ /* =semlit,endblock,includes=*/ -main() +int main(int argc, char **argv) { /* =semlit,block,variables=*/ lbm_context_t *ctx; /* Context object */ @@ -101,5 +101,6 @@ main() #if defined(_MSC_VER) WSACleanup(); #endif + return 0; } diff --git a/source_notify_callbacks/c/source_notify_callbacks.c b/source_notify_callbacks/c/source_notify_callbacks.c index 0c8712f..0ee081b 100644 --- a/source_notify_callbacks/c/source_notify_callbacks.c +++ b/source_notify_callbacks/c/source_notify_callbacks.c @@ -1,4 +1,24 @@ -/* source_notify_callback.c - http://ultramessaging.github.io/UMExamples */ +/* source_notify_callbacks.c - see http://ultramessaging.github.io/UMExamples/source_notify_callbacks/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + #include #if defined(_MSC_VER) @@ -13,98 +33,117 @@ #endif #include +/* State structure associated with each source the receiver is joined to. */ +typedef struct source_state_s { + int msgs_rcvd; /* Track message count from each source. */ +} source_state_t; + /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) -int new_src_notification_callback(const char *source_name, void *clientd) + +void *new_src_notification_callback(const char *source_name, void *clientd) { - printf("Delivery Controller Created: %s\n", source_name); - return 0; -} + source_state_t *source_state = (source_state_t *)malloc(sizeof(source_state_t)); + source_state->msgs_rcvd = 0; + + printf("Delivery Controller Created: %s\n", source_name); + return source_state; /* This will be available in the receive callback as msg->source_clientd. */ +} /* new_src_notification_callback */ + int src_delete_notification_callback(const char *source_name, void *clientd, void* src_clientd ) { - printf("Delivery Controller Deleted: %s\n", source_name); - return 0; -} + free(src_clientd); /* This was created by new_src_notification_callback() */ + + printf("Delivery Controller Deleted: %s\n", source_name); + return 0; +} /* src_delete_notification_callback */ + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - - switch (msg->type) { - case LBM_MSG_BOS: - printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); - break; - case LBM_MSG_EOS: - printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); - break; - default: - printf("Other event, type=%x\n", msg->type); - break; - } - - return 0; -} - -main() + source_state_t *source_state = (source_state_t *)msg->source_clientd; + + switch (msg->type) { + case LBM_MSG_DATA: + source_state->msgs_rcvd ++; + printf("[%s][%s], Received message %d\n", msg->topic_name, msg->source, source_state->msgs_rcvd); + break; + case LBM_MSG_BOS: + printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); + break; + case LBM_MSG_EOS: + printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); + break; + default: + printf("Other event, type=%x\n", msg->type); + break; + } + + return 0; +} /* rcv_handle_msg */ + + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ - lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 context atrributes and create context */ - err = lbm_context_create(&ctx, NULL, NULL, NULL); - EX_LBM_CHK(err); + /* Initialize context atrributes and create context */ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - /* Create receiver for receiving request and sending response */ - err = lbm_rcv_topic_attr_create(&rattr); - EX_LBM_CHK(err); + /* Create receiver for receiving request and sending response */ + err = lbm_rcv_topic_attr_create(&rattr); + EX_LBM_CHK(err); - srccb.create_func = new_src_notification_callback; - srccb.delete_func = src_delete_notification_callback; + srccb.create_func = new_src_notification_callback; + srccb.delete_func = src_delete_notification_callback; - err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); - EX_LBM_CHK(err); + err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); + EX_LBM_CHK(err); - err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); + err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); EX_LBM_CHK(err); - err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); - EX_LBM_CHK(err); + err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); + EX_LBM_CHK(err); - while (1) { } + /* Wait forever (or until control-c). */ + while (1) { } - err = lbm_rcv_delete(rcv); - EX_LBM_CHK(err); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif + return 0; } /* main */ diff --git a/source_notify_callbacks/c/source_notify_callbacks.sldoc b/source_notify_callbacks/c/source_notify_callbacks.sldoc index fdabebe..4391a5c 100644 --- a/source_notify_callbacks/c/source_notify_callbacks.sldoc +++ b/source_notify_callbacks/c/source_notify_callbacks.sldoc @@ -12,11 +12,18 @@ Program explanation: source_notify_callbacks.c
+Per-source State Information
+As new sources are discovered for the receiver, the user wants to create and maintain some state information + associated with that source. In this simple example, just keep a per-source count of messages received.
+ =semlit,insert,state=Delivery Controller Create Callback
Here the user callback for the delivery controller being created is defined. This function will execute every time a source is detected (when a source's topic advertisement is received by the receiver's context) that the - receiver is interested in. This callback will execute before a BOS would because BOS required data on the transport - to be received, unlike this function which just requires a TIR on an interested source.
+ receiver is interested in. + UM expects the function to return a pointer to the state information, which + will subsequently be passed to the receive callback as msg->source_clientd. + This callback will execute before a BOS would because BOS required data on the transport + to be received, unlike this function which just requires a TIR on an interested source.
=semlit,insert,create_cb=Delivery Controller Delete Callback
This is the user callback for when the delivery controller is deleted. A delivery controller would be deleted diff --git a/source_notify_callbacks/c/source_notify_callbacks.sldoc.html b/source_notify_callbacks/c/source_notify_callbacks.sldoc.html index e28f56c..7d0644a 100644 --- a/source_notify_callbacks/c/source_notify_callbacks.sldoc.html +++ b/source_notify_callbacks/c/source_notify_callbacks.sldoc.html @@ -7,7 +7,8 @@ Example index
Receiver Source Notification Callbacks (Create and Delete)
This example demonstrates how to configure and code the callbacks for when a receiver creates and deletes a - delivery controller for a specific source.
+ delivery controller for a specific source. This is typically done in support of maintaining per-source + state information.Like many other callback function in UM, the source notification is configured via a receiver attribute, +
+00036 /* State structure associated with each source the receiver is joined to. */ +00037 typedef struct source_state_s { +00038 int msgs_rcvd; /* Track message count from each source. */ +00039 } source_state_t; ++ +Delivery Controller Create Callback
Here the user callback for the delivery controller being created is defined. This function will execute every time a source is detected (when a source's topic advertisement is received by the receiver's context) that the - receiver is interested in. This callback will execute before a BOS would because BOS required data on the transport - to be received, unlike this function which just requires a TIR on an interested source.
+ receiver is interested in. + UM expects the function to return a pointer to the state information, which + will subsequently be passed to the receive callback as msg->source_clientd. + This callback will execute before a BOS would because BOS required data on the transport + to be received, unlike this function which just requires a TIR on an interested source.
-00025 int new_src_notification_callback(const char *source_name, void *clientd) -00026 { -00027 printf("Delivery Controller Created: %s\n", source_name); -00028 return 0; -00029 } +00051 void *new_src_notification_callback(const char *source_name, void *clientd) +00052 { +00053 source_state_t *source_state = (source_state_t *)malloc(sizeof(source_state_t)); +00054 source_state->msgs_rcvd = 0; +00055 +00056 printf("Delivery Controller Created: %s\n", source_name); +00057 return source_state; /* This will be available in the receive callback as msg->source_clientd. */ +00058 } /* new_src_notification_callback */@@ -65,11 +83,13 @@Delivery Controller Delete Callback
to rely on this callback versus EOS, because this callback is guaranteed if no data has been received for the topic.-00031 int src_delete_notification_callback(const char *source_name, void *clientd, void* src_clientd ) -00032 { -00033 printf("Delivery Controller Deleted: %s\n", source_name); -00034 return 0; -00035 } +00061 int src_delete_notification_callback(const char *source_name, void *clientd, void* src_clientd ) +00062 { +00063 free(src_clientd); /* This was created by new_src_notification_callback() */ +00064 +00065 printf("Delivery Controller Deleted: %s\n", source_name); +00066 return 0; +00067 } /* src_delete_notification_callback */@@ -77,24 +97,29 @@Standard Receive Callback
This is the standard receiver callback where messages are processed, as well as events like BOS and EOS
-00038 int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) -00039 { -00040 int err; -00041 -00042 switch (msg->type) { -00043 case LBM_MSG_BOS: -00044 printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); -00045 break; -00046 case LBM_MSG_EOS: -00047 printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); -00048 break; -00049 default: -00050 printf("Other event, type=%x\n", msg->type); -00051 break; -00052 } -00053 -00054 return 0; -00055 } +00070 /* Callback used to handle request message for receiver */ +00071 int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +00072 { +00073 source_state_t *source_state = (source_state_t *)msg->source_clientd; +00074 +00075 switch (msg->type) { +00076 case LBM_MSG_DATA: +00077 source_state->msgs_rcvd ++; +00078 printf("[%s][%s], Received message %d\n", msg->topic_name, msg->source, source_state->msgs_rcvd); +00079 break; +00080 case LBM_MSG_BOS: +00081 printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); +00082 break; +00083 case LBM_MSG_EOS: +00084 printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); +00085 break; +00086 default: +00087 printf("Other event, type=%x\n", msg->type); +00088 break; +00089 } +00090 +00091 return 0; +00092 } /* rcv_handle_msg */@@ -112,7 +137,7 @@Declare Notify Structure
must be used to set the user callbacks which have been defined above.-00064 lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ +00101 lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */@@ -121,11 +146,11 @@Set the Callbacks and Configure Parameter
the API to configure the paramter:-00086 srccb.create_func = new_src_notification_callback; -00087 srccb.delete_func = src_delete_notification_callback; -00088 -00089 err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); -00090 EX_LBM_CHK(err); +00123 srccb.create_func = new_src_notification_callback; +00124 srccb.delete_func = src_delete_notification_callback; +00125 +00126 err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); +00127 EX_LBM_CHK(err);@@ -134,19 +159,19 @@Includes
are not necessary for Linux only applications-00002 #include <stdio.h> -00003 -00004 #if defined(_MSC_VER) -00005 /* Windows-only includes */ -00006 #include <winsock2.h> -00007 #define SLEEP(s) Sleep((s)*1000) -00008 #else -00009 /* Unix-only includes */ -00010 #include <stdlib.h> -00011 #include <unistd.h> -00012 #define SLEEP(s) sleep(s) -00013 #endif -00014 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 #include <lbm/lbm.h>@@ -154,16 +179,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00067 #if defined(_WIN32) -00068 /* windows-specific code */ -00069 WSADATA wsadata; -00070 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00071 if (wsStat != 0) -00072 { -00073 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00074 exit(1); -00075 } -00076 #endif +00104 #if defined(_WIN32) +00105 /* windows-specific code */ +00106 WSADATA wsadata; +00107 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00108 if (wsStat != 0) +00109 { +00110 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00111 exit(1); +00112 } +00113 #endifdiff --git a/source_notify_callbacks/c/source_notify_callbacks_c.slsrc b/source_notify_callbacks/c/source_notify_callbacks_c.slsrc index 7e42520..edc8456 100644 --- a/source_notify_callbacks/c/source_notify_callbacks_c.slsrc +++ b/source_notify_callbacks/c/source_notify_callbacks_c.slsrc @@ -1,4 +1,24 @@ -/* source_notify_callback.c - http://ultramessaging.github.io/UMExamples */ +/* source_notify_callbacks.c - see http://ultramessaging.github.io/UMExamples/source_notify_callbacks/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + /* =semlit,block,includes=*/ #include@@ -15,110 +35,131 @@ #include /* =semlit,endblock,includes=*/ +/* =semlit,block,state=*/ +/* State structure associated with each source the receiver is joined to. */ +typedef struct source_state_s { + int msgs_rcvd; /* Track message count from each source. */ +} source_state_t; +/* =semlit,endblock,state=*/ + /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* =semlit,block,create_cb=*/ -int new_src_notification_callback(const char *source_name, void *clientd) +void *new_src_notification_callback(const char *source_name, void *clientd) { - printf("Delivery Controller Created: %s\n", source_name); - return 0; -} + source_state_t *source_state = (source_state_t *)malloc(sizeof(source_state_t)); + source_state->msgs_rcvd = 0; + + printf("Delivery Controller Created: %s\n", source_name); + return source_state; /* This will be available in the receive callback as msg->source_clientd. */ +} /* new_src_notification_callback */ /* =semlit,endblock,create_cb=*/ + /* =semlit,block,delete_cb=*/ int src_delete_notification_callback(const char *source_name, void *clientd, void* src_clientd ) { - printf("Delivery Controller Deleted: %s\n", source_name); - return 0; -} + free(src_clientd); /* This was created by new_src_notification_callback() */ + + printf("Delivery Controller Deleted: %s\n", source_name); + return 0; +} /* src_delete_notification_callback */ /* =semlit,endblock,delete_cb=*/ -/* Callback used to handle request message for receiver */ + /* =semlit,block,receive_cb=*/ +/* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - - switch (msg->type) { - case LBM_MSG_BOS: - printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); - break; - case LBM_MSG_EOS: - printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); - break; - default: - printf("Other event, type=%x\n", msg->type); - break; - } - - return 0; -} + source_state_t *source_state = (source_state_t *)msg->source_clientd; + + switch (msg->type) { + case LBM_MSG_DATA: + source_state->msgs_rcvd ++; + printf("[%s][%s], Received message %d\n", msg->topic_name, msg->source, source_state->msgs_rcvd); + break; + case LBM_MSG_BOS: + printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); + break; + case LBM_MSG_EOS: + printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); + break; + default: + printf("Other event, type=%x\n", msg->type); + break; + } + + return 0; +} /* rcv_handle_msg */ /* =semlit,endblock,receive_cb=*/ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ /* =semlit,block,srccb_var=*/ - lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ + lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ /* =semlit,endblock,srccb_var=*/ - int err; /* Used for checking API return codes */ + int err; /* =semlit,block,windows=*/ #if defined(_WIN32) - /* 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); - } + /* 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 /* =semlit,endblock,windows=*/ - /* Initialize context atrributes and create context */ - err = lbm_context_create(&ctx, NULL, NULL, NULL); - EX_LBM_CHK(err); + /* Initialize context atrributes and create context */ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - /* Create receiver for receiving request and sending response */ - err = lbm_rcv_topic_attr_create(&rattr); - EX_LBM_CHK(err); + /* Create receiver for receiving request and sending response */ + err = lbm_rcv_topic_attr_create(&rattr); + EX_LBM_CHK(err); /* =semlit,block,set_cbs=*/ - srccb.create_func = new_src_notification_callback; - srccb.delete_func = src_delete_notification_callback; + srccb.create_func = new_src_notification_callback; + srccb.delete_func = src_delete_notification_callback; - err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); - EX_LBM_CHK(err); + err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); + EX_LBM_CHK(err); /* =semlit,endblock,set_cbs=*/ - err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); + err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); EX_LBM_CHK(err); - err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); - EX_LBM_CHK(err); + err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); + EX_LBM_CHK(err); - while (1) { } + /* Wait forever (or until control-c). */ + while (1) { } - err = lbm_rcv_delete(rcv); - EX_LBM_CHK(err); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif + return 0; } /* main */ diff --git a/source_notify_callbacks/c/source_notify_callbacks_c.slsrc.html b/source_notify_callbacks/c/source_notify_callbacks_c.slsrc.html index b53bc88..5055c02 100644 --- a/source_notify_callbacks/c/source_notify_callbacks_c.slsrc.html +++ b/source_notify_callbacks/c/source_notify_callbacks_c.slsrc.html @@ -17,19 +17,19 @@ diff --git a/source_notify_callbacks/dotnet/source_notify_callbacks.sldoc.html b/source_notify_callbacks/dotnet/source_notify_callbacks.sldoc.html index d51fa29..dc3a112 100644 --- a/source_notify_callbacks/dotnet/source_notify_callbacks.sldoc.html +++ b/source_notify_callbacks/dotnet/source_notify_callbacks.sldoc.html @@ -7,7 +7,8 @@ Example index
00001 -00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 +00002 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 00015 00016 00017 @@ -37,77 +37,77 @@ 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 00059 00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 00093 00094 00095 @@ -116,17 +116,76 @@ 00098 00099 00100 -00101 +00101 00102 00103 -00104 -00105 -00106 -00107 -00108 -00109 -00110 - /* source_notify_callback.c - http://ultramessaging.github.io/UMExamples */ +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 +00149 + /* source_notify_callbacks.c - see http://ultramessaging.github.io/UMExamples/source_notify_callbacks/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + #include <stdio.h> #if defined(_MSC_VER) @@ -141,100 +200,119 @@ #endif #include <lbm/lbm.h> + /* State structure associated with each source the receiver is joined to. */ + typedef struct source_state_s { + int msgs_rcvd; /* Track message count from each source. */ + } source_state_t; + /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) - int new_src_notification_callback(const char *source_name, void *clientd) + + void *new_src_notification_callback(const char *source_name, void *clientd) { - printf("Delivery Controller Created: %s\n", source_name); - return 0; - } + source_state_t *source_state = (source_state_t *)malloc(sizeof(source_state_t)); + source_state->msgs_rcvd = 0; + + printf("Delivery Controller Created: %s\n", source_name); + return source_state; /* This will be available in the receive callback as msg->source_clientd. */ + } /* new_src_notification_callback */ + int src_delete_notification_callback(const char *source_name, void *clientd, void* src_clientd ) { - printf("Delivery Controller Deleted: %s\n", source_name); - return 0; - } + free(src_clientd); /* This was created by new_src_notification_callback() */ + + printf("Delivery Controller Deleted: %s\n", source_name); + return 0; + } /* src_delete_notification_callback */ + - /* Callback used to handle request message for receiver */ - int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) + /* Callback used to handle request message for receiver */ + int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; + source_state_t *source_state = (source_state_t *)msg->source_clientd; - switch (msg->type) { - case LBM_MSG_BOS: - printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); - break; - case LBM_MSG_EOS: - printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); - break; - default: - printf("Other event, type=%x\n", msg->type); - break; - } + switch (msg->type) { + case LBM_MSG_DATA: + source_state->msgs_rcvd ++; + printf("[%s][%s], Received message %d\n", msg->topic_name, msg->source, source_state->msgs_rcvd); + break; + case LBM_MSG_BOS: + printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); + break; + case LBM_MSG_EOS: + printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); + break; + default: + printf("Other event, type=%x\n", msg->type); + break; + } - return 0; - } + return 0; + } /* rcv_handle_msg */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ - lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + lbm_rcv_topic_attr_t * rattr; /* Receiver attribute object */ + lbm_rcv_src_notification_func_t srccb; /* Source notify callback structure */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 context atrributes and create context */ - err = lbm_context_create(&ctx, NULL, NULL, NULL); - EX_LBM_CHK(err); + /* Initialize context atrributes and create context */ + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); - /* Create receiver for receiving request and sending response */ - err = lbm_rcv_topic_attr_create(&rattr); - EX_LBM_CHK(err); + /* Create receiver for receiving request and sending response */ + err = lbm_rcv_topic_attr_create(&rattr); + EX_LBM_CHK(err); - srccb.create_func = new_src_notification_callback; - srccb.delete_func = src_delete_notification_callback; + srccb.create_func = new_src_notification_callback; + srccb.delete_func = src_delete_notification_callback; - err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); - EX_LBM_CHK(err); + err = lbm_rcv_topic_attr_setopt(rattr, "source_notification_function", &srccb, sizeof(srccb)); + EX_LBM_CHK(err); - err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); + err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", rattr); EX_LBM_CHK(err); - err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); - EX_LBM_CHK(err); + err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); + EX_LBM_CHK(err); - while (1) { } + /* Wait forever (or until control-c). */ + while (1) { } - err = lbm_rcv_delete(rcv); - EX_LBM_CHK(err); + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); - err = lbm_context_delete(ctx); - EX_LBM_CHK(err); + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); #if defined(_MSC_VER) - /* Windows-specific cleanup overhead */ - WSACleanup(); + /* Windows-specific cleanup overhead */ + WSACleanup(); #endif + return 0; } /* main */ Receiver Source Notification Callbacks (Create and Delete)
This example demonstrates how to configure and code the callbacks for when a receiver creates and deletes a - delivery controller for a specific source.
+ delivery controller for a specific source. This is typically done in support of maintaining per-source + state information.Like many other callback function in UM, the source notification is configured via a receiver attribute, Example index
Receiver Source Notification Callbacks (Create and Delete)
This example demonstrates how to configure and code the callbacks for when a receiver creates and deletes a - delivery controller for a specific source.
+ delivery controller for a specific source. This is typically done in support of maintaining per-source + state information.Like many other callback function in UM, the source notification is configured via a receiver attribute, =semlit,tooltip,../../tooltips/receiver_source_notification_function.txt,source_notification_function=which must be set programatically so that the appropriate function pointers can be provided.
@@ -19,5 +20,4 @@ to help debug networking issues. However, this callback is not great at telling the application that a specific topic ready to start receiving messages. Instead, the application can use the source_notification_callback which is demonstrated in this sample application. The source_notification_callback can enable a user callback to be executed - when delivery controller is created for a topic and a separate callback for when a delivery controller is deleted. -+ when delivery controller is created for a topic and a separate callback for when a delivery controller is deleted.
diff --git a/source_notify_callbacks/java/source_notify_callbacks.sldoc.html b/source_notify_callbacks/java/source_notify_callbacks.sldoc.html index 2ff05a8..5b3227d 100644 --- a/source_notify_callbacks/java/source_notify_callbacks.sldoc.html +++ b/source_notify_callbacks/java/source_notify_callbacks.sldoc.html @@ -7,7 +7,8 @@ Example indexReceiver Source Notification Callbacks (Create and Delete)
This example demonstrates how to configure and code the callbacks for when a receiver creates and deletes a - delivery controller for a specific source.
+ delivery controller for a specific source. This is typically done in support of maintaining per-source + state information.Like many other callback function in UM, the source notification is configured via a receiver attribute, +#include
+ +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define MSLEEP(s) Sleep(s) /* Portable millisecond sleep. */ +#else +/* Unix-only includes */ +#include +#include +#define MSLEEP(s) usleep((s) * 1000) /* Portable millisecond sleep. */ +#endif + +#include + +typedef struct server_s { + lbm_context_t *ctx; + char *topic_name; /* Topic the server is subscribed to. */ + lbm_src_t *src; /* Source to send requests to server. */ + lbm_rcv_t *rcv; /* Receiver for responses from server. */ + int state; /* 0=Waiting for registration, 1=registered. */ +} server_t; + +/* Header for request messages. */ +typedef struct req_hdr_s { + char data[8]; +} req_hdr_t; + + +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + +int response_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +{ + server_t *server = (server_t *)clientd; + req_hdr_t *req_hdr; + const char *req_data; + + switch (msg->type) + { + case LBM_MSG_DATA: /* Received a message from the client. */ + printf("Received %ld bytes on topic %s: '%.*s'\n", + (long)msg->len, msg->topic_name, (int)msg->len, msg->data); + + if (msg->len > 1 && msg->data[0] == 'r') { + /* Should check for success. */ + server->state = 1; /* Registered. */ + } + else if (msg->len > sizeof(req_hdr_t) && msg->data[0] == 'R') { + req_hdr = (req_hdr_t *)msg->data; + req_data = &msg->data[sizeof(req_hdr_t)]; + /* Process response message. */ + } + break; + + case LBM_MSG_BOS: + printf("[%s][%s], BOS\n", msg->topic_name, msg->source); + break; + + case LBM_MSG_EOS: + printf("[%s][%s], EOS\n", msg->topic_name, msg->source); + break; + + default: /* unexpected receiver event */ + printf("Receive event type %d topic='%s', source='%s'\n", + msg->type, msg->topic_name, msg->source); + break; + } /* switch msg->type */ + + return 0; +} /* response_rcv_cb */ + + +int main(int argc, char **argv) +{ + lbm_context_t *ctx; + server_t server; /* State information for the server. */ + char response_topic_name[256]; + int err; + + /* Get (pretty much) unique client name. */ + sprintf(response_topic_name, "Client.%lx.Response", (long)getpid()); + +#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 + + server.ctx = NULL; + + server.topic_name = "Server1.Request"; + server.src = NULL; /* Source to send requests to server. */ + server.rcv = NULL; /* Receiver for responses from server. */ + server.state = 0; /* Waiting for registration. */ + + err = lbm_config("client.cfg"); + EX_LBM_CHK(err); + + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + server.ctx = ctx; + + /* Create source to send requests to server. */ + { + lbm_topic_t *topic; + err = lbm_src_topic_alloc(&topic, ctx, server.topic_name, NULL); + EX_LBM_CHK(err); + err = lbm_src_create(&server.src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + } + + /* Create receiver for responses from server. */ + { + lbm_topic_t *topic; + err = lbm_rcv_topic_lookup(&topic, ctx, response_topic_name, NULL); + EX_LBM_CHK(err); + err = lbm_rcv_create(&server.rcv, ctx, topic, response_rcv_cb, &server, NULL); + EX_LBM_CHK(err); + } + + /* Register with the server. May need multiple tries. */ + { + int try_cnt = 0; + int backoff_delay; + char register_msg[257]; + sprintf(register_msg, "r%s", response_topic_name); + + backoff_delay = 1; /* In milliseconds. */ + MSLEEP(backoff_delay); /* Let TR complete. */ + while (server.state == 0) { + try_cnt ++; + err = lbm_src_send(server.src, register_msg, + strlen(register_msg) + 1, LBM_MSG_FLUSH | LBM_SRC_BLOCK); + EX_LBM_CHK(err); + printf("Sent '%s' to %s\n", register_msg, server.topic_name); + + /* Exponential backoff, to max of 1 sec. */ + backoff_delay *= 2; /* Exponential backoff to max of 1 sec. */ + if (backoff_delay > 1000) { + backoff_delay = 1000; + } + MSLEEP(backoff_delay); /* Wait for server response. */ + } + printf("Took %d tries to register with server.\n", try_cnt); + } + + /* Main work of the program, which includes sending 5 requests. */ + { + int i; + char send_buf[500]; + req_hdr_t *req_hdr = (req_hdr_t *)send_buf; + + memset((char *)req_hdr, '0', sizeof(req_hdr_t)); + req_hdr->data[0] = 'R'; + + for (i = 0; i < 5; i++) { + /* The application builds a request into request_msg. */ + char request_msg[257]; + sprintf(request_msg, "%s.%d", response_topic_name, i); + + /* The application message is copied in after the header. */ + strcpy(&send_buf[sizeof(req_hdr_t)], request_msg); + err = lbm_src_send(server.src, send_buf, strlen(send_buf) + 1, + LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + MSLEEP(1000); + } + } + + printf("Client exiting.\n"); + err = lbm_rcv_delete(server.rcv); + EX_LBM_CHK(err); + err = lbm_src_delete(server.src); + EX_LBM_CHK(err); + + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + +#if defined(_MSC_VER) + WSACleanup(); +#endif + + return 0; +} /* main */ diff --git a/src_rsp/c/client_c.slsrc b/src_rsp/c/client_c.slsrc new file mode 100644 index 0000000..0897587 --- /dev/null +++ b/src_rsp/c/client_c.slsrc @@ -0,0 +1,235 @@ +/* client.c - see http://ultramessaging.github.io/UMExamples/client/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + +#include +#include + +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define MSLEEP(s) Sleep(s) /* Portable millisecond sleep. */ +#else +/* Unix-only includes */ +#include +#include +#define MSLEEP(s) usleep((s) * 1000) /* Portable millisecond sleep. */ +#endif + +#include + +typedef struct server_s { + lbm_context_t *ctx; + char *topic_name; /* Topic the server is subscribed to. */ + lbm_src_t *src; /* Source to send requests to server. */ + lbm_rcv_t *rcv; /* Receiver for responses from server. */ + int state; /* 0=Waiting for registration, 1=registered. */ +} server_t; + +/* Header for request messages. */ +typedef struct req_hdr_s { + char data[8]; +} req_hdr_t; + + +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + + +int response_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +{ + server_t *server = (server_t *)clientd; + req_hdr_t *req_hdr; + const char *req_data; + + switch (msg->type) + { +/* =semlit,block,register_done= */ + case LBM_MSG_DATA: /* Received a message from the client. */ + printf("Received %ld bytes on topic %s: '%.*s'\n", + (long)msg->len, msg->topic_name, (int)msg->len, msg->data); + + if (msg->len > 1 && msg->data[0] == 'r') { + /* Should check for success. */ + server->state = 1; /* Registered. */ + } +/* =semlit,endblock,register_done= */ + else if (msg->len > sizeof(req_hdr_t) && msg->data[0] == 'R') { + req_hdr = (req_hdr_t *)msg->data; + req_data = &msg->data[sizeof(req_hdr_t)]; + /* Process response message. */ + } + break; + + case LBM_MSG_BOS: + printf("[%s][%s], BOS\n", msg->topic_name, msg->source); + break; + + case LBM_MSG_EOS: + printf("[%s][%s], EOS\n", msg->topic_name, msg->source); + break; + + default: /* unexpected receiver event */ + printf("Receive event type %d topic='%s', source='%s'\n", + msg->type, msg->topic_name, msg->source); + break; + } /* switch msg->type */ + + return 0; +} /* response_rcv_cb */ + + +int main(int argc, char **argv) +{ + lbm_context_t *ctx; + server_t server; /* State information for the server. */ + char response_topic_name[256]; + int err; + +/* =semlit,block,client_name= */ + /* Get (pretty much) unique client name. */ + sprintf(response_topic_name, "Client.%lx.Response", (long)getpid()); +/* =semlit,endblock,client_name= */ + +#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 + + server.ctx = NULL; + +/* =semlit,block,server_name= */ + server.topic_name = "Server1.Request"; +/* =semlit,endblock,server_name= */ + server.src = NULL; /* Source to send requests to server. */ + server.rcv = NULL; /* Receiver for responses from server. */ + server.state = 0; /* Waiting for registration. */ + + err = lbm_config("client.cfg"); + EX_LBM_CHK(err); + + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + server.ctx = ctx; + +/* =semlit,block,req_src_create= */ + /* Create source to send requests to server. */ + { + lbm_topic_t *topic; + err = lbm_src_topic_alloc(&topic, ctx, server.topic_name, NULL); + EX_LBM_CHK(err); + err = lbm_src_create(&server.src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + } +/* =semlit,endblock,req_src_create= */ + +/* =semlit,block,rsp_rcv_create= */ + /* Create receiver for responses from server. */ + { + lbm_topic_t *topic; + err = lbm_rcv_topic_lookup(&topic, ctx, response_topic_name, NULL); + EX_LBM_CHK(err); + err = lbm_rcv_create(&server.rcv, ctx, topic, response_rcv_cb, &server, NULL); + EX_LBM_CHK(err); + } +/* =semlit,endblock,rsp_rcv_create= */ + + /* Register with the server. May need multiple tries. */ + { + int try_cnt = 0; + int backoff_delay; +/* =semlit,block,register_msg= */ + char register_msg[257]; + sprintf(register_msg, "r%s", response_topic_name); +/* =semlit,endblock,register_msg= */ + +/* =semlit,block,register_loop= */ + backoff_delay = 1; /* In milliseconds. */ + MSLEEP(backoff_delay); /* Let TR complete. */ + while (server.state == 0) { + try_cnt ++; + err = lbm_src_send(server.src, register_msg, + strlen(register_msg) + 1, LBM_MSG_FLUSH | LBM_SRC_BLOCK); + EX_LBM_CHK(err); + printf("Sent '%s' to %s\n", register_msg, server.topic_name); + + /* Exponential backoff, to max of 1 sec. */ + backoff_delay *= 2; /* Exponential backoff to max of 1 sec. */ + if (backoff_delay > 1000) { + backoff_delay = 1000; + } + MSLEEP(backoff_delay); /* Wait for server response. */ + } + printf("Took %d tries to register with server.\n", try_cnt); +/* =semlit,endblock,register_loop= */ + } + + /* Main work of the program, which includes sending 5 requests. */ + { + int i; +/* =semlit,block,req_buf= */ + char send_buf[500]; + req_hdr_t *req_hdr = (req_hdr_t *)send_buf; + + memset((char *)req_hdr, '0', sizeof(req_hdr_t)); + req_hdr->data[0] = 'R'; +/* =semlit,endblock,req_buf= */ + +/* =semlit,block,req_sends= */ + for (i = 0; i < 5; i++) { + /* The application builds a request into request_msg. */ + char request_msg[257]; + sprintf(request_msg, "%s.%d", response_topic_name, i); + + /* The application message is copied in after the header. */ + strcpy(&send_buf[sizeof(req_hdr_t)], request_msg); + err = lbm_src_send(server.src, send_buf, strlen(send_buf) + 1, + LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + MSLEEP(1000); + } +/* =semlit,endblock,req_sends= */ + } + + printf("Client exiting.\n"); + err = lbm_rcv_delete(server.rcv); + EX_LBM_CHK(err); + err = lbm_src_delete(server.src); + EX_LBM_CHK(err); + + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + +#if defined(_MSC_VER) + WSACleanup(); +#endif + + return 0; +} /* main */ diff --git a/src_rsp/c/client_c.slsrc.html b/src_rsp/c/client_c.slsrc.html new file mode 100644 index 0000000..d474a0b --- /dev/null +++ b/src_rsp/c/client_c.slsrc.html @@ -0,0 +1,538 @@ + client.c + + + + + + + + +client.c
+ +diff --git a/src_rsp/c/index.html b/src_rsp/c/index.html new file mode 100644 index 0000000..0beb962 --- /dev/null +++ b/src_rsp/c/index.html @@ -0,0 +1,6 @@ + + + diff --git a/src_rsp/c/server.c b/src_rsp/c/server.c new file mode 100644 index 0000000..76b729c --- /dev/null +++ b/src_rsp/c/server.c @@ -0,0 +1,302 @@ +/* server.c - see http://ultramessaging.github.io/UMExamples/server/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + +#include+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 00001 +00002 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 +00017 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 +00149 +00150 +00151 +00152 +00153 +00154 +00155 +00156 +00157 +00158 +00159 +00160 +00161 +00162 +00163 +00164 +00165 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 +00181 +00182 +00183 +00184 +00185 +00186 +00187 +00188 +00189 +00190 +00191 +00192 +00193 +00194 +00195 +00196 +00197 +00198 +00199 +00200 +00201 +00202 +00203 +00204 +00205 +00206 +00207 +00208 +00209 +00210 +00211 +00212 +00213 +00214 +00215 +00216 +00217 + /* client.c - see http://ultramessaging.github.io/UMExamples/client/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + + #include <stdio.h> + #include <string.h> + + #if defined(_MSC_VER) + /* Windows-only includes */ + #include <winsock2.h> + #define MSLEEP(s) Sleep(s) /* Portable millisecond sleep. */ + #else + /* Unix-only includes */ + #include <stdlib.h> + #include <unistd.h> + #define MSLEEP(s) usleep((s) * 1000) /* Portable millisecond sleep. */ + #endif + + #include <lbm/lbm.h> + + typedef struct server_s { + lbm_context_t *ctx; + char *topic_name; /* Topic the server is subscribed to. */ + lbm_src_t *src; /* Source to send requests to server. */ + lbm_rcv_t *rcv; /* Receiver for responses from server. */ + int state; /* 0=Waiting for registration, 1=registered. */ + } server_t; + + /* Header for request messages. */ + typedef struct req_hdr_s { + char data[8]; + } req_hdr_t; + + + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + + int response_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) + { + server_t *server = (server_t *)clientd; + req_hdr_t *req_hdr; + const char *req_data; + + switch (msg->type) + { + case LBM_MSG_DATA: /* Received a message from the client. */ + printf("Received %ld bytes on topic %s: '%.*s'\n", + (long)msg->len, msg->topic_name, (int)msg->len, msg->data); + + if (msg->len > 1 && msg->data[0] == 'r') { + /* Should check for success. */ + server->state = 1; /* Registered. */ + } + else if (msg->len > sizeof(req_hdr_t) && msg->data[0] == 'R') { + req_hdr = (req_hdr_t *)msg->data; + req_data = &msg->data[sizeof(req_hdr_t)]; + /* Process response message. */ + } + break; + + case LBM_MSG_BOS: + printf("[%s][%s], BOS\n", msg->topic_name, msg->source); + break; + + case LBM_MSG_EOS: + printf("[%s][%s], EOS\n", msg->topic_name, msg->source); + break; + + default: /* unexpected receiver event */ + printf("Receive event type %d topic='%s', source='%s'\n", + msg->type, msg->topic_name, msg->source); + break; + } /* switch msg->type */ + + return 0; + } /* response_rcv_cb */ + + + int main(int argc, char **argv) + { + lbm_context_t *ctx; + server_t server; /* State information for the server. */ + char response_topic_name[256]; + int err; + + /* Get (pretty much) unique client name. */ + sprintf(response_topic_name, "Client.%lx.Response", (long)getpid()); + + #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 + + server.ctx = NULL; + + server.topic_name = "Server1.Request"; + server.src = NULL; /* Source to send requests to server. */ + server.rcv = NULL; /* Receiver for responses from server. */ + server.state = 0; /* Waiting for registration. */ + + err = lbm_config("client.cfg"); + EX_LBM_CHK(err); + + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + server.ctx = ctx; + + /* Create source to send requests to server. */ + { + lbm_topic_t *topic; + err = lbm_src_topic_alloc(&topic, ctx, server.topic_name, NULL); + EX_LBM_CHK(err); + err = lbm_src_create(&server.src, ctx, topic, NULL, NULL, NULL); + EX_LBM_CHK(err); + } + + /* Create receiver for responses from server. */ + { + lbm_topic_t *topic; + err = lbm_rcv_topic_lookup(&topic, ctx, response_topic_name, NULL); + EX_LBM_CHK(err); + err = lbm_rcv_create(&server.rcv, ctx, topic, response_rcv_cb, &server, NULL); + EX_LBM_CHK(err); + } + + /* Register with the server. May need multiple tries. */ + { + int try_cnt = 0; + int backoff_delay; + char register_msg[257]; + sprintf(register_msg, "r%s", response_topic_name); + + backoff_delay = 1; /* In milliseconds. */ + MSLEEP(backoff_delay); /* Let TR complete. */ + while (server.state == 0) { + try_cnt ++; + err = lbm_src_send(server.src, register_msg, + strlen(register_msg) + 1, LBM_MSG_FLUSH | LBM_SRC_BLOCK); + EX_LBM_CHK(err); + printf("Sent '%s' to %s\n", register_msg, server.topic_name); + + /* Exponential backoff, to max of 1 sec. */ + backoff_delay *= 2; /* Exponential backoff to max of 1 sec. */ + if (backoff_delay > 1000) { + backoff_delay = 1000; + } + MSLEEP(backoff_delay); /* Wait for server response. */ + } + printf("Took %d tries to register with server.\n", try_cnt); + } + + /* Main work of the program, which includes sending 5 requests. */ + { + int i; + char send_buf[500]; + req_hdr_t *req_hdr = (req_hdr_t *)send_buf; + + memset((char *)req_hdr, '0', sizeof(req_hdr_t)); + req_hdr->data[0] = 'R'; + + for (i = 0; i < 5; i++) { + /* The application builds a request into <tt>request_msg</tt>. */ + char request_msg[257]; + sprintf(request_msg, "%s.%d", response_topic_name, i); + + /* The application message is copied in after the header. */ + strcpy(&send_buf[sizeof(req_hdr_t)], request_msg); + err = lbm_src_send(server.src, send_buf, strlen(send_buf) + 1, + LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + MSLEEP(1000); + } + } + + printf("Client exiting.\n"); + err = lbm_rcv_delete(server.rcv); + EX_LBM_CHK(err); + err = lbm_src_delete(server.src); + EX_LBM_CHK(err); + + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + + #if defined(_MSC_VER) + WSACleanup(); + #endif + + return 0; + } /* main */ + +#include + +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define SLEEP(s) Sleep((s)*1000) +#else +/* Unix-only includes */ +#include +#include +#define SLEEP(s) sleep(s) +#endif + +#include + + +/* Header for request messages. */ +typedef struct req_hdr_s { + char data[8]; +} req_hdr_t; + + +#define MAX_RESP_SIZE 7000 +typedef struct client_s { + int state; /* 0=waiting for registration, 1=registered. */ + char *topic_name; + char *source_name; + lbm_context_t *ctx; + lbm_src_t *resp_src; + char send_buf[MAX_RESP_SIZE + sizeof(req_hdr_t)]; +} client_t; + +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + +/* Error if null. */ +#define NULL_CHK(N_ptr) do { \ + if ((N_ptr) == NULL) { \ + fprintf(stderr, "Error, %s:%d: '%s' is NULL\n", \ + __FILE__, __LINE__, #N_ptr); \ + fflush(stderr); \ + abort(); /* core dump */ \ + } \ +} while (0) + + +void handle_register(client_t *client, const char *client_resp_name) +{ + int err; + /* This work should probably be passed to a separate worker thread, but + * I'll do it here to simplify the code. */ + + if (client->state == 1) { + printf("Source '%s' re-confirmed\n", client->topic_name); + /* Reply to client. */ + err = lbm_src_send(client->resp_src, "rOK", 4, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + } + else if (client->state == 0) { + lbm_src_topic_attr_t * src_attr; + lbm_topic_t *lbm_topic; + + /* Create source to send responses to client. */ + err = lbm_src_topic_attr_create(&src_attr); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, "transport", "lbt-ru"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, "transport_lbtru_port", "12070"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, + "transport_source_side_filtering_behavior", "inclusion"); + EX_LBM_CHK(err); + err = lbm_src_topic_alloc(&lbm_topic, client->ctx, client_resp_name, src_attr); + EX_LBM_CHK(err); + /* The following create can fail if a new client joins with the same + * response topic name as an existing client. Should handle this cleanly. */ + err = lbm_src_create(&client->resp_src, client->ctx, lbm_topic, + NULL, NULL, NULL); + if (err) { + printf("Source '%s' failed; %s\n", client_resp_name, lbm_errmsg()); + } + else { + client->state = 1; + client->topic_name = strdup(client_resp_name); + NULL_CHK(client->topic_name); + printf("Source '%s' created\n", client->topic_name); + } + + err = lbm_src_topic_attr_delete(src_attr); + EX_LBM_CHK(err); + } +} /* handle_register */ + + +void handle_req(client_t *client, req_hdr_t *req_hdr, const char *req_msg, size_t len) +{ + int err; + + /* This work should probably be passed to a separate worker thread, but + * I'll do it here to simplify the code. */ + + /* Responses copy the header from the request. */ + memcpy(&client->send_buf[0], (char *)req_hdr, sizeof(req_hdr_t)); + /* Response message is put after the header. */ + char *response_msg = &client->send_buf[sizeof(req_hdr_t)]; + + /* Do the work of the request and put the response in response_msg. + * (For this sample, just echo back the request.) */ + strcpy(response_msg, req_msg); + + /* Reply to client. */ + err = lbm_src_send(client->resp_src, client->send_buf, + strlen(client->send_buf) + 1, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + printf("sent response to '%s'.\n", client->topic_name); +} /* handle_req */ + + +int request_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +{ + client_t *client = (client_t *)msg->source_clientd; + + switch (msg->type) + { + case LBM_MSG_DATA: /* Received a message from the client. */ + printf("Received %ld bytes on topic %s: '%.*s'\n", + (long)msg->len, msg->topic_name, (int)msg->len, msg->data); + + /* Register message. */ + if (msg->len > 1 && msg->data[0] == 'r') { + handle_register(client, &msg->data[1]); + } + + /* Request message. */ + else if (msg->len >= sizeof(req_hdr_t) && msg->data[0] == 'R') { + req_hdr_t req_hdr; + memcpy((char *)&req_hdr, msg->data, sizeof(req_hdr_t)); + + handle_req(client, &req_hdr, &msg->data[sizeof(req_hdr_t)], + msg->len - sizeof(req_hdr_t)); + } + else { + printf("Ignored unrecognized command '%c'\n", msg->data[0]); + break; + } + break; + + case LBM_MSG_BOS: + printf("[%s][%s], BOS\n", msg->topic_name, msg->source); + break; + + case LBM_MSG_EOS: + printf("[%s][%s], EOS\n", msg->topic_name, msg->source); + break; + + default: /* unexpected receiver event */ + printf("Receive event type %x topic='%s', source='%s'\n", msg->type, msg->topic_name, msg->source); + break; + } /* switch msg->type */ + + return 0; +} /* request_rcv_cb */ + + +void *start_client_source(const char *source_name, void *clientd) +{ + lbm_context_t *ctx = (lbm_context_t *)clientd;; + client_t *new_client = (client_t *)malloc(sizeof(client_t)); + NULL_CHK(new_client); + + new_client->state = 0; /* Waiting for register. */ + new_client->topic_name = NULL; + new_client->source_name = strdup(source_name); + NULL_CHK(new_client->source_name); + new_client->ctx = ctx; + new_client->resp_src = NULL; + + return new_client; +} /* start_client_source */ + + +int end_client_source(const char *source_name, void *clientd, void *source_clientd) +{ + int err; + + if (source_clientd) { + client_t *client = (client_t *)source_clientd; + + if (client->topic_name) { + free(client->topic_name); + } + if (client->source_name) { + free(client->source_name); + } + + err = lbm_src_delete(client->resp_src); + EX_LBM_CHK(err); + + free(source_clientd); + } + + return 0; +} /* end_client_source */ + + +int main(int argc, char **argv) +{ + lbm_context_t *ctx; + lbm_rcv_t *rcv; /* Receiver for requests from clients. */ + int err; + +#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 + + err = lbm_config("serv.cfg"); + EX_LBM_CHK(err); + + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + + /* Create receiver for requests from clients. */ + { + lbm_rcv_src_notification_func_t source_notification_function; + lbm_rcv_topic_attr_t *rcv_attr; + lbm_topic_t *topic; + + err = lbm_rcv_topic_attr_create(&rcv_attr); + EX_LBM_CHK(err); + + /* Set up per-source state management. */ + source_notification_function.create_func = start_client_source; + source_notification_function.delete_func = end_client_source; + source_notification_function.clientd = ctx; /* Pass this to start_client_source(). */ + err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", + &source_notification_function, sizeof(source_notification_function)); + EX_LBM_CHK(err); + + err = lbm_rcv_topic_lookup(&topic, ctx, "Server1.Request", rcv_attr); + EX_LBM_CHK(err); + /* Pass context object as clientd. */ + err = lbm_rcv_create(&rcv, ctx, topic, request_rcv_cb, ctx, NULL); + EX_LBM_CHK(err); + + err = lbm_rcv_topic_attr_delete(rcv_attr); + EX_LBM_CHK(err); + } + + while (1) { + SLEEP(1); + } + + /* Finished all receiving from this topic, delete the receiver object. */ + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + + /* Do not need to delete the topic object - LBM keeps track of topic + * objects and deletes them as-needed. */ + + /* Finished with all LBM functions, delete the context object. */ + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + +#if defined(_MSC_VER) + WSACleanup(); +#endif + + return 0; +} /* main */ diff --git a/src_rsp/c/server_c.slsrc b/src_rsp/c/server_c.slsrc new file mode 100644 index 0000000..a92079b --- /dev/null +++ b/src_rsp/c/server_c.slsrc @@ -0,0 +1,324 @@ +/* server.c - see http://ultramessaging.github.io/UMExamples/server/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + +#include +#include + +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define SLEEP(s) Sleep((s)*1000) +#else +/* Unix-only includes */ +#include +#include +#define SLEEP(s) sleep(s) +#endif + +#include + + +/* Header for request messages. */ +typedef struct req_hdr_s { + char data[8]; +} req_hdr_t; + + +#define MAX_RESP_SIZE 7000 +typedef struct client_s { + int state; /* 0=waiting for registration, 1=registered. */ + char *topic_name; + char *source_name; + lbm_context_t *ctx; + lbm_src_t *resp_src; + char send_buf[MAX_RESP_SIZE + sizeof(req_hdr_t)]; +} client_t; + +/* Example error checking macro. Include after each UM call. */ +#define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ +} while (0) + +/* Error if null. */ +#define NULL_CHK(N_ptr) do { \ + if ((N_ptr) == NULL) { \ + fprintf(stderr, "Error, %s:%d: '%s' is NULL\n", \ + __FILE__, __LINE__, #N_ptr); \ + fflush(stderr); \ + abort(); /* core dump */ \ + } \ +} while (0) + + +/* =semlit,block,do_reg2= */ +void handle_register(client_t *client, const char *client_resp_name) +{ + int err; + /* This work should probably be passed to a separate worker thread, but + * I'll do it here to simplify the code. */ + +/* =semlit,block,rsp_src_ok= */ + if (client->state == 1) { + printf("Source '%s' re-confirmed\n", client->topic_name); + /* Reply to client. */ + err = lbm_src_send(client->resp_src, "rOK", 4, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + } +/* =semlit,endblock,rsp_src_ok= */ + else if (client->state == 0) { + lbm_src_topic_attr_t * src_attr; + lbm_topic_t *lbm_topic; + + /* Create source to send responses to client. */ + err = lbm_src_topic_attr_create(&src_attr); + EX_LBM_CHK(err); +/* =semlit,block,rsp_src_config= */ + err = lbm_src_topic_attr_str_setopt(src_attr, "transport", "lbt-ru"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, "transport_lbtru_port", "12070"); + EX_LBM_CHK(err); +/* =semlit,endblock,rsp_src_config= */ +/* =semlit,block,rsp_src_config2= */ + err = lbm_src_topic_attr_str_setopt(src_attr, + "transport_source_side_filtering_behavior", "inclusion"); + EX_LBM_CHK(err); +/* =semlit,endblock,rsp_src_config2= */ + err = lbm_src_topic_alloc(&lbm_topic, client->ctx, client_resp_name, src_attr); + EX_LBM_CHK(err); + /* The following create can fail if a new client joins with the same + * response topic name as an existing client. Should handle this cleanly. */ + err = lbm_src_create(&client->resp_src, client->ctx, lbm_topic, + NULL, NULL, NULL); + if (err) { + printf("Source '%s' failed; %s\n", client_resp_name, lbm_errmsg()); + } + else { +/* =semlit,block,rsp_src_created= */ + client->state = 1; + client->topic_name = strdup(client_resp_name); + NULL_CHK(client->topic_name); + printf("Source '%s' created\n", client->topic_name); +/* =semlit,endblock,rsp_src_created= */ + } + + err = lbm_src_topic_attr_delete(src_attr); + EX_LBM_CHK(err); + } +} /* handle_register */ +/* =semlit,endblock,do_reg2= */ + + +/* =semlit,block,do_req2= */ +void handle_req(client_t *client, req_hdr_t *req_hdr, const char *req_msg, size_t len) +{ + int err; + + /* This work should probably be passed to a separate worker thread, but + * I'll do it here to simplify the code. */ + + /* Responses copy the header from the request. */ + memcpy(&client->send_buf[0], (char *)req_hdr, sizeof(req_hdr_t)); + /* Response message is put after the header. */ + char *response_msg = &client->send_buf[sizeof(req_hdr_t)]; + + /* Do the work of the request and put the response in response_msg. + * (For this sample, just echo back the request.) */ + strcpy(response_msg, req_msg); + + /* Reply to client. */ + err = lbm_src_send(client->resp_src, client->send_buf, + strlen(client->send_buf) + 1, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + printf("sent response to '%s'.\n", client->topic_name); +} /* handle_req */ +/* =semlit,endblock,do_req2= */ + + +/* =semlit,block,do_reg0= */ +int request_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +{ + client_t *client = (client_t *)msg->source_clientd; +/* =semlit,endblock,do_reg0= */ + + switch (msg->type) + { +/* =semlit,block,do_reg1= */ + case LBM_MSG_DATA: /* Received a message from the client. */ + printf("Received %ld bytes on topic %s: '%.*s'\n", + (long)msg->len, msg->topic_name, (int)msg->len, msg->data); + + /* Register message. */ + if (msg->len > 1 && msg->data[0] == 'r') { + handle_register(client, &msg->data[1]); + } +/* =semlit,endblock,do_reg1= */ + +/* =semlit,block,do_req1= */ + /* Request message. */ + else if (msg->len >= sizeof(req_hdr_t) && msg->data[0] == 'R') { + req_hdr_t req_hdr; + memcpy((char *)&req_hdr, msg->data, sizeof(req_hdr_t)); + + handle_req(client, &req_hdr, &msg->data[sizeof(req_hdr_t)], + msg->len - sizeof(req_hdr_t)); + } +/* =semlit,endblock,do_req1= */ + else { + printf("Ignored unrecognized command '%c'\n", msg->data[0]); + break; + } + break; + + case LBM_MSG_BOS: + printf("[%s][%s], BOS\n", msg->topic_name, msg->source); + break; + + case LBM_MSG_EOS: + printf("[%s][%s], EOS\n", msg->topic_name, msg->source); + break; + + default: /* unexpected receiver event */ + printf("Receive event type %x topic='%s', source='%s'\n", msg->type, msg->topic_name, msg->source); + break; + } /* switch msg->type */ + + return 0; +} /* request_rcv_cb */ + + +/* =semlit,block,start_client= */ +void *start_client_source(const char *source_name, void *clientd) +{ + lbm_context_t *ctx = (lbm_context_t *)clientd;; + client_t *new_client = (client_t *)malloc(sizeof(client_t)); + NULL_CHK(new_client); + + new_client->state = 0; /* Waiting for register. */ + new_client->topic_name = NULL; + new_client->source_name = strdup(source_name); + NULL_CHK(new_client->source_name); + new_client->ctx = ctx; + new_client->resp_src = NULL; + + return new_client; +} /* start_client_source */ +/* =semlit,endblock,start_client= */ + + +int end_client_source(const char *source_name, void *clientd, void *source_clientd) +{ + int err; + + if (source_clientd) { + client_t *client = (client_t *)source_clientd; + + if (client->topic_name) { + free(client->topic_name); + } + if (client->source_name) { + free(client->source_name); + } + + err = lbm_src_delete(client->resp_src); + EX_LBM_CHK(err); + + free(source_clientd); + } + + return 0; +} /* end_client_source */ + + +int main(int argc, char **argv) +{ + lbm_context_t *ctx; + lbm_rcv_t *rcv; /* Receiver for requests from clients. */ + int err; + +#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 + + err = lbm_config("serv.cfg"); + EX_LBM_CHK(err); + + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + + /* Create receiver for requests from clients. */ + { +/* =semlit,block,src_notif_setopt= */ + lbm_rcv_src_notification_func_t source_notification_function; + lbm_rcv_topic_attr_t *rcv_attr; + lbm_topic_t *topic; + + err = lbm_rcv_topic_attr_create(&rcv_attr); + EX_LBM_CHK(err); + + /* Set up per-source state management. */ + source_notification_function.create_func = start_client_source; + source_notification_function.delete_func = end_client_source; + source_notification_function.clientd = ctx; /* Pass this to start_client_source(). */ + err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", + &source_notification_function, sizeof(source_notification_function)); + EX_LBM_CHK(err); + + err = lbm_rcv_topic_lookup(&topic, ctx, "Server1.Request", rcv_attr); + EX_LBM_CHK(err); + /* Pass context object as clientd. */ + err = lbm_rcv_create(&rcv, ctx, topic, request_rcv_cb, ctx, NULL); + EX_LBM_CHK(err); + + err = lbm_rcv_topic_attr_delete(rcv_attr); + EX_LBM_CHK(err); + } +/* =semlit,endblock,src_notif_setopt= */ + + while (1) { + SLEEP(1); + } + + /* Finished all receiving from this topic, delete the receiver object. */ + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + + /* Do not need to delete the topic object - LBM keeps track of topic + * objects and deletes them as-needed. */ + + /* Finished with all LBM functions, delete the context object. */ + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + +#if defined(_MSC_VER) + WSACleanup(); +#endif + + return 0; +} /* main */ diff --git a/src_rsp/c/server_c.slsrc.html b/src_rsp/c/server_c.slsrc.html new file mode 100644 index 0000000..afcc945 --- /dev/null +++ b/src_rsp/c/server_c.slsrc.html @@ -0,0 +1,708 @@ + server.c + + + + + + + + +server.c
+ +diff --git a/src_rsp/c/src_rsp.sldoc b/src_rsp/c/src_rsp.sldoc new file mode 100644 index 0000000..a98ef37 --- /dev/null +++ b/src_rsp/c/src_rsp.sldoc @@ -0,0 +1,197 @@ + + + ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 00001 +00002 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 +00017 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 +00149 +00150 +00151 +00152 +00153 +00154 +00155 +00156 +00157 +00158 +00159 +00160 +00161 +00162 +00163 +00164 +00165 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 +00181 +00182 +00183 +00184 +00185 +00186 +00187 +00188 +00189 +00190 +00191 +00192 +00193 +00194 +00195 +00196 +00197 +00198 +00199 +00200 +00201 +00202 +00203 +00204 +00205 +00206 +00207 +00208 +00209 +00210 +00211 +00212 +00213 +00214 +00215 +00216 +00217 +00218 +00219 +00220 +00221 +00222 +00223 +00224 +00225 +00226 +00227 +00228 +00229 +00230 +00231 +00232 +00233 +00234 +00235 +00236 +00237 +00238 +00239 +00240 +00241 +00242 +00243 +00244 +00245 +00246 +00247 +00248 +00249 +00250 +00251 +00252 +00253 +00254 +00255 +00256 +00257 +00258 +00259 +00260 +00261 +00262 +00263 +00264 +00265 +00266 +00267 +00268 +00269 +00270 +00271 +00272 +00273 +00274 +00275 +00276 +00277 +00278 +00279 +00280 +00281 +00282 +00283 +00284 +00285 +00286 +00287 +00288 +00289 +00290 +00291 +00292 +00293 +00294 +00295 +00296 +00297 +00298 +00299 +00300 +00301 +00302 + /* server.c - see http://ultramessaging.github.io/UMExamples/server/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + + #include <stdio.h> + #include <string.h> + + #if defined(_MSC_VER) + /* Windows-only includes */ + #include <winsock2.h> + #define SLEEP(s) Sleep((s)*1000) + #else + /* Unix-only includes */ + #include <stdlib.h> + #include <unistd.h> + #define SLEEP(s) sleep(s) + #endif + + #include <lbm/lbm.h> + + + /* Header for request messages. */ + typedef struct req_hdr_s { + char data[8]; + } req_hdr_t; + + + #define MAX_RESP_SIZE 7000 + typedef struct client_s { + int state; /* 0=waiting for registration, 1=registered. */ + char *topic_name; + char *source_name; + lbm_context_t *ctx; + lbm_src_t *resp_src; + char send_buf[MAX_RESP_SIZE + sizeof(req_hdr_t)]; + } client_t; + + /* Example error checking macro. Include after each UM call. */ + #define EX_LBM_CHK(err) do { \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ + } while (0) + + /* Error if null. */ + #define NULL_CHK(N_ptr) do { \ + if ((N_ptr) == NULL) { \ + fprintf(stderr, "Error, %s:%d: '%s' is NULL\n", \ + __FILE__, __LINE__, #N_ptr); \ + fflush(stderr); \ + abort(); /* core dump */ \ + } \ + } while (0) + + + void handle_register(client_t *client, const char *client_resp_name) + { + int err; + /* This work should probably be passed to a separate worker thread, but + * I'll do it here to simplify the code. */ + + if (client->state == 1) { + printf("Source '%s' re-confirmed\n", client->topic_name); + /* Reply to client. */ + err = lbm_src_send(client->resp_src, "rOK", 4, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + } + else if (client->state == 0) { + lbm_src_topic_attr_t * src_attr; + lbm_topic_t *lbm_topic; + + /* Create source to send responses to client. */ + err = lbm_src_topic_attr_create(&src_attr); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, "transport", "lbt-ru"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, "transport_lbtru_port", "12070"); + EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(src_attr, + "transport_source_side_filtering_behavior", "inclusion"); + EX_LBM_CHK(err); + err = lbm_src_topic_alloc(&lbm_topic, client->ctx, client_resp_name, src_attr); + EX_LBM_CHK(err); + /* The following create can fail if a new client joins with the same + * response topic name as an existing client. Should handle this cleanly. */ + err = lbm_src_create(&client->resp_src, client->ctx, lbm_topic, + NULL, NULL, NULL); + if (err) { + printf("Source '%s' failed; %s\n", client_resp_name, lbm_errmsg()); + } + else { + client->state = 1; + client->topic_name = strdup(client_resp_name); + NULL_CHK(client->topic_name); + printf("Source '%s' created\n", client->topic_name); + } + + err = lbm_src_topic_attr_delete(src_attr); + EX_LBM_CHK(err); + } + } /* handle_register */ + + + void handle_req(client_t *client, req_hdr_t *req_hdr, const char *req_msg, size_t len) + { + int err; + + /* This work should probably be passed to a separate worker thread, but + * I'll do it here to simplify the code. */ + + /* Responses copy the header from the request. */ + memcpy(&client->send_buf[0], (char *)req_hdr, sizeof(req_hdr_t)); + /* Response message is put after the header. */ + char *response_msg = &client->send_buf[sizeof(req_hdr_t)]; + + /* Do the work of the request and put the response in response_msg. + * (For this sample, just echo back the request.) */ + strcpy(response_msg, req_msg); + + /* Reply to client. */ + err = lbm_src_send(client->resp_src, client->send_buf, + strlen(client->send_buf) + 1, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); + EX_LBM_CHK(err); + printf("sent response to '%s'.\n", client->topic_name); + } /* handle_req */ + + + int request_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) + { + client_t *client = (client_t *)msg->source_clientd; + + switch (msg->type) + { + case LBM_MSG_DATA: /* Received a message from the client. */ + printf("Received %ld bytes on topic %s: '%.*s'\n", + (long)msg->len, msg->topic_name, (int)msg->len, msg->data); + + /* Register message. */ + if (msg->len > 1 && msg->data[0] == 'r') { + handle_register(client, &msg->data[1]); + } + + /* Request message. */ + else if (msg->len >= sizeof(req_hdr_t) && msg->data[0] == 'R') { + req_hdr_t req_hdr; + memcpy((char *)&req_hdr, msg->data, sizeof(req_hdr_t)); + + handle_req(client, &req_hdr, &msg->data[sizeof(req_hdr_t)], + msg->len - sizeof(req_hdr_t)); + } + else { + printf("Ignored unrecognized command '%c'\n", msg->data[0]); + break; + } + break; + + case LBM_MSG_BOS: + printf("[%s][%s], BOS\n", msg->topic_name, msg->source); + break; + + case LBM_MSG_EOS: + printf("[%s][%s], EOS\n", msg->topic_name, msg->source); + break; + + default: /* unexpected receiver event */ + printf("Receive event type %x topic='%s', source='%s'\n", msg->type, msg->topic_name, msg->source); + break; + } /* switch msg->type */ + + return 0; + } /* request_rcv_cb */ + + + void *start_client_source(const char *source_name, void *clientd) + { + lbm_context_t *ctx = (lbm_context_t *)clientd;; + client_t *new_client = (client_t *)malloc(sizeof(client_t)); + NULL_CHK(new_client); + + new_client->state = 0; /* Waiting for register. */ + new_client->topic_name = NULL; + new_client->source_name = strdup(source_name); + NULL_CHK(new_client->source_name); + new_client->ctx = ctx; + new_client->resp_src = NULL; + + return new_client; + } /* start_client_source */ + + + int end_client_source(const char *source_name, void *clientd, void *source_clientd) + { + int err; + + if (source_clientd) { + client_t *client = (client_t *)source_clientd; + + if (client->topic_name) { + free(client->topic_name); + } + if (client->source_name) { + free(client->source_name); + } + + err = lbm_src_delete(client->resp_src); + EX_LBM_CHK(err); + + free(source_clientd); + } + + return 0; + } /* end_client_source */ + + + int main(int argc, char **argv) + { + lbm_context_t *ctx; + lbm_rcv_t *rcv; /* Receiver for requests from clients. */ + int err; + + #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 + + err = lbm_config("serv.cfg"); + EX_LBM_CHK(err); + + err = lbm_context_create(&ctx, NULL, NULL, NULL); + EX_LBM_CHK(err); + + /* Create receiver for requests from clients. */ + { + lbm_rcv_src_notification_func_t source_notification_function; + lbm_rcv_topic_attr_t *rcv_attr; + lbm_topic_t *topic; + + err = lbm_rcv_topic_attr_create(&rcv_attr); + EX_LBM_CHK(err); + + /* Set up per-source state management. */ + source_notification_function.create_func = start_client_source; + source_notification_function.delete_func = end_client_source; + source_notification_function.clientd = ctx; /* Pass this to start_client_source(). */ + err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", + &source_notification_function, sizeof(source_notification_function)); + EX_LBM_CHK(err); + + err = lbm_rcv_topic_lookup(&topic, ctx, "Server1.Request", rcv_attr); + EX_LBM_CHK(err); + /* Pass context object as clientd. */ + err = lbm_rcv_create(&rcv, ctx, topic, request_rcv_cb, ctx, NULL); + EX_LBM_CHK(err); + + err = lbm_rcv_topic_attr_delete(rcv_attr); + EX_LBM_CHK(err); + } + + while (1) { + SLEEP(1); + } + + /* Finished all receiving from this topic, delete the receiver object. */ + err = lbm_rcv_delete(rcv); + EX_LBM_CHK(err); + + /* Do not need to delete the topic object - LBM keeps track of topic + * objects and deletes them as-needed. */ + + /* Finished with all LBM functions, delete the context object. */ + err = lbm_context_delete(ctx); + EX_LBM_CHK(err); + + #if defined(_MSC_VER) + WSACleanup(); + #endif + + return 0; + } /* main */ + Source-based Request/Response + + + Example index + +How to use sources to send requests and responses.
+ +There are two source files associated with this example:
++
+ +- =semlit,srcfile,client_c.slsrc,client.c= + - (right-click and save as "client.c").
+- =semlit,srcfile,server_c.slsrc,server.c= + - (right-click and save as "server.c").
+The UM "request/response" feature provides a convenient, easy-to-code + method for a classic server program to respond to a request sent by a client. + The feature takes care of routing the server's response message back to + the client that sent the request. + It also associates response messages with the corresponding request + messages, even if multiple messages are outstanding. + See Request-Response Sample.
+ +However, there are advantages for the server to use a normal UM + source to send response messages:
++
+ +- Choice of transport types. + UM responses are always sent with TCP. + +
- Reliability settings for non-TCP transports are under user control. + Can be configured to recover messages after long network outages. + +
- Extra layer of reliability. + The "OTR" feature can recover messages unrecoverably lost by the + transport. + Also, the source can be made persistent for even greater reliability. + +
- Better application visibility. + Receivers get BOS, EOS, and unrecoverable loss events, and for + unicast transport types, sources get connect and disconnect events. + +
- UDP-based transport types can give lower latency. +
This sample program uses an LBT-RU source to return response messages + to the requesting client program.
+ +Overall Approach
+ +Clients use a UM source to send a request to a server, and the server + uses a UM receiver to receive it. + The server then uses a UM source to send a response back to only the + client that sent the request, and that client uses a UM receiver to + receive it. + This sample allows and arbitrary number of client programs to come and + go, without the server being pre-configured to know about them.
+ +When a client program initializes, it creates a source to send + requests and a receiver to receive responses. + The client then exchanges handshakes with the server to register with it, + and to verify round-trip connectivity. + This verification avoids initial message loss during topic resolution.
+ +Registration
+ +The client uses the server's well-known request topic to create + the source.
+ + =semlit,insert,server_name= +. . .
+ =semlit,insert,req_src_create= + +The client needs a unique topic to receive is responses. + Using the process PID is an easy, but non-robust method (two + clients on different machines can have the same PID).
+ + =semlit,insert,client_name= +. . .
+ =semlit,insert,rsp_rcv_create= + +Registration: Client Side
+ +The registration message that the client sends to the server is + all-ascii, consisting of lower-case 'r' followed by a null-terminated + topic name on which the client receives responses.
+ + =semlit,insert,register_msg= + +The client sends registration messages repeatedly in a loop, with + exponential backoff delays. + For example, if the server is not running, the client sends registration + attempts at 1, 2, 4, 8, ... milliseconds, to a maximum of 1 second.
+ + =semlit,insert,register_loop= + +The loop exits when the client receives a registration response.
+ + =semlit,insert,register_done= + +Registration: Server Side
+ +The server makes use of source notification create/delete callbacks + to manage client state. + The callbacks are configured as part of creation of the server's + main receiver.
+ + =semlit,insert,src_notif_setopt= + +Then, when the receiver discovers a new client's source, + start_client_source() is called. + That function only creates the state structure associated with the + new client.
+ + =semlit,insert,start_client= + +When the client sends its registration message, it is received by + the server, which uses it to create the source used for sending + responses. + The state structure created above is passed to the receiver + callback in msg->source_clientd.
+ + =semlit,insert,do_reg0= + +Registration requests start with the character 'r'.
+ + =semlit,insert,do_reg1= +. . .
+ =semlit,insert,do_reg2= + +The response source is created in a special way. + It is an LBT-RU transport type, with a fixed port number (the choice + of 12070 was arbitrary). + This means that all clients' sources are mapped to the same LBT-RU + transport session.
+ + =semlit,insert,rsp_src_config= + +To prevent each client's responses from being sent to all clients, + source-side filtering is enabled.
+ + =semlit,insert,rsp_src_config2= + +On successful source creation, the client state is filled in. + But no reply is sent to the client. + This is because the client has not yet had a chance to discover and + join the new source, so any message sent at this point would not + be delivered.
+ + =semlit,insert,rsp_src_created= + +The server could set some kind of timer to send its reply, but + to simplify this code, we just wait for the client to retry. + When the next registration request comes in, we send the OK + message. + Thus, it will always take at least 2 tries to register.
+ + =semlit,insert,rsp_src_ok= + +Request/Response
+ +This example does not contain the code necessary to associate responses + with their requests. + However, the simple protocol was designed to allow this to be added. + A request message consists of an 8-ascii-byte header followed by the + application message content. + The first byte of the header is the character 'R' to indicate a request + message. + The other 7 bytes are currently just set to ascii '0' characters, but + could be used as a request ID. + When the server responds to requests, it uses the same header it + received, so the client can maintain a table of outstanding requests. + This logic is not included in this example.
+ +Request: Client Side
+ +In this example, the send buffer for requests is declared as an + arbitrary large buffer. + The header is initialized once.
+ + =semlit,insert,req_buf= + +For this simple example, 5 requests are sent.
+ + =semlit,insert,req_sends= + +Response: Server Side
+ +When the server receives the request, it sends a response.
+ + =semlit,insert,do_req1= +. . .
+ =semlit,insert,do_req2= + + diff --git a/src_rsp/c/src_rsp.sldoc.html b/src_rsp/c/src_rsp.sldoc.html new file mode 100644 index 0000000..5f2de63 --- /dev/null +++ b/src_rsp/c/src_rsp.sldoc.html @@ -0,0 +1,484 @@ + + + +Source-based Request/Response + + + Example index + +How to use sources to send requests and responses.
+ +There are two source files associated with this example:
++
+ +- client.c + - (right-click and save as "client.c").
+- server.c + - (right-click and save as "server.c").
+The UM "request/response" feature provides a convenient, easy-to-code + method for a classic server program to respond to a request sent by a client. + The feature takes care of routing the server's response message back to + the client that sent the request. + It also associates response messages with the corresponding request + messages, even if multiple messages are outstanding. + See Request-Response Sample.
+ +However, there are advantages for the server to use a normal UM + source to send response messages:
++
+ +- Choice of transport types. + UM responses are always sent with TCP. + +
- Reliability settings for non-TCP transports are under user control. + Can be configured to recover messages after long network outages. + +
- Extra layer of reliability. + The "OTR" feature can recover messages unrecoverably lost by the + transport. + Also, the source can be made persistent for even greater reliability. + +
- Better application visibility. + Receivers get BOS, EOS, and unrecoverable loss events, and for + unicast transport types, sources get connect and disconnect events. + +
- UDP-based transport types can give lower latency. +
This sample program uses an LBT-RU source to return response messages + to the requesting client program.
+ +Overall Approach
+ +Clients use a UM source to send a request to a server, and the server + uses a UM receiver to receive it. + The server then uses a UM source to send a response back to only the + client that sent the request, and that client uses a UM receiver to + receive it. + This sample allows and arbitrary number of client programs to come and + go, without the server being pre-configured to know about them.
+ +When a client program initializes, it creates a source to send + requests and a receiver to receive responses. + The client then exchanges handshakes with the server to register with it, + and to verify round-trip connectivity. + This verification avoids initial message loss during topic resolution.
+ +Registration
+ +The client uses the server's well-known request topic to create + the source.
+ + ++00124 server.topic_name = "Server1.Request"; ++ + +. . .
+ ++00136 /* Create source to send requests to server. */ +00137 { +00138 lbm_topic_t *topic; +00139 err = lbm_src_topic_alloc(&topic, ctx, server.topic_name, NULL); +00140 EX_LBM_CHK(err); +00141 err = lbm_src_create(&server.src, ctx, topic, NULL, NULL, NULL); +00142 EX_LBM_CHK(err); +00143 } ++ + + +The client needs a unique topic to receive is responses. + Using the process PID is an easy, but non-robust method (two + clients on different machines can have the same PID).
+ + ++00110 /* Get (pretty much) unique client name. */ +00111 sprintf(response_topic_name, "Client.%lx.Response", (long)getpid()); ++ + +. . .
+ ++00145 /* Create receiver for responses from server. */ +00146 { +00147 lbm_topic_t *topic; +00148 err = lbm_rcv_topic_lookup(&topic, ctx, response_topic_name, NULL); +00149 EX_LBM_CHK(err); +00150 err = lbm_rcv_create(&server.rcv, ctx, topic, response_rcv_cb, &server, NULL); +00151 EX_LBM_CHK(err); +00152 } ++ + + +Registration: Client Side
+ +The registration message that the client sends to the server is + all-ascii, consisting of lower-case 'r' followed by a null-terminated + topic name on which the client receives responses.
+ + ++00158 char register_msg[257]; +00159 sprintf(register_msg, "r%s", response_topic_name); ++ + + +The client sends registration messages repeatedly in a loop, with + exponential backoff delays. + For example, if the server is not running, the client sends registration + attempts at 1, 2, 4, 8, ... milliseconds, to a maximum of 1 second.
+ + ++00161 backoff_delay = 1; /* In milliseconds. */ +00162 MSLEEP(backoff_delay); /* Let TR complete. */ +00163 while (server.state == 0) { +00164 try_cnt ++; +00165 err = lbm_src_send(server.src, register_msg, +00166 strlen(register_msg) + 1, LBM_MSG_FLUSH | LBM_SRC_BLOCK); +00167 EX_LBM_CHK(err); +00168 printf("Sent '%s' to %s\n", register_msg, server.topic_name); +00169 +00170 /* Exponential backoff, to max of 1 sec. */ +00171 backoff_delay *= 2; /* Exponential backoff to max of 1 sec. */ +00172 if (backoff_delay > 1000) { +00173 backoff_delay = 1000; +00174 } +00175 MSLEEP(backoff_delay); /* Wait for server response. */ +00176 } +00177 printf("Took %d tries to register with server.\n", try_cnt); ++ + + +The loop exits when the client receives a registration response.
+ + ++00070 case LBM_MSG_DATA: /* Received a message from the client. */ +00071 printf("Received %ld bytes on topic %s: '%.*s'\n", +00072 (long)msg->len, msg->topic_name, (int)msg->len, msg->data); +00073 +00074 if (msg->len > 1 && msg->data[0] == 'r') { +00075 /* Should check for success. */ +00076 server->state = 1; /* Registered. */ +00077 } ++ + + +Registration: Server Side
+ +The server makes use of source notification create/delete callbacks + to manage client state. + The callbacks are configured as part of creation of the server's + main receiver.
+ + ++00257 lbm_rcv_src_notification_func_t source_notification_function; +00258 lbm_rcv_topic_attr_t *rcv_attr; +00259 lbm_topic_t *topic; +00260 +00261 err = lbm_rcv_topic_attr_create(&rcv_attr); +00262 EX_LBM_CHK(err); +00263 +00264 /* Set up per-source state management. */ +00265 source_notification_function.create_func = start_client_source; +00266 source_notification_function.delete_func = end_client_source; +00267 source_notification_function.clientd = ctx; /* Pass this to start_client_source(). */ +00268 err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", +00269 &source_notification_function, sizeof(source_notification_function)); +00270 EX_LBM_CHK(err); +00271 +00272 err = lbm_rcv_topic_lookup(&topic, ctx, "Server1.Request", rcv_attr); +00273 EX_LBM_CHK(err); +00274 /* Pass context object as clientd. */ +00275 err = lbm_rcv_create(&rcv, ctx, topic, request_rcv_cb, ctx, NULL); +00276 EX_LBM_CHK(err); +00277 +00278 err = lbm_rcv_topic_attr_delete(rcv_attr); +00279 EX_LBM_CHK(err); +00280 } ++ + + +Then, when the receiver discovers a new client's source, + start_client_source() is called. + That function only creates the state structure associated with the + new client.
+ + ++00193 void *start_client_source(const char *source_name, void *clientd) +00194 { +00195 lbm_context_t *ctx = (lbm_context_t *)clientd;; +00196 client_t *new_client = (client_t *)malloc(sizeof(client_t)); +00197 NULL_CHK(new_client); +00198 +00199 new_client->state = 0; /* Waiting for register. */ +00200 new_client->topic_name = NULL; +00201 new_client->source_name = strdup(source_name); +00202 NULL_CHK(new_client->source_name); +00203 new_client->ctx = ctx; +00204 new_client->resp_src = NULL; +00205 +00206 return new_client; +00207 } /* start_client_source */ ++ + + +When the client sends its registration message, it is received by + the server, which uses it to create the source used for sending + responses. + The state structure created above is passed to the receiver + callback in msg->source_clientd.
+ + ++00147 int request_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +00148 { +00149 client_t *client = (client_t *)msg->source_clientd; ++ + + +Registration requests start with the character 'r'.
+ + ++00153 case LBM_MSG_DATA: /* Received a message from the client. */ +00154 printf("Received %ld bytes on topic %s: '%.*s'\n", +00155 (long)msg->len, msg->topic_name, (int)msg->len, msg->data); +00156 +00157 /* Register message. */ +00158 if (msg->len > 1 && msg->data[0] == 'r') { +00159 handle_register(client, &msg->data[1]); +00160 } ++ + +. . .
+ ++00075 void handle_register(client_t *client, const char *client_resp_name) +00076 { +00077 int err; +00078 /* This work should probably be passed to a separate worker thread, but +00079 * I'll do it here to simplify the code. */ +00080 +00081 if (client->state == 1) { +00082 printf("Source '%s' re-confirmed\n", client->topic_name); +00083 /* Reply to client. */ +00084 err = lbm_src_send(client->resp_src, "rOK", 4, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); +00085 EX_LBM_CHK(err); +00086 } +00087 else if (client->state == 0) { +00088 lbm_src_topic_attr_t * src_attr; +00089 lbm_topic_t *lbm_topic; +00090 +00091 /* Create source to send responses to client. */ +00092 err = lbm_src_topic_attr_create(&src_attr); +00093 EX_LBM_CHK(err); +00094 err = lbm_src_topic_attr_str_setopt(src_attr, "transport", "lbt-ru"); +00095 EX_LBM_CHK(err); +00096 err = lbm_src_topic_attr_str_setopt(src_attr, "transport_lbtru_port", "12070"); +00097 EX_LBM_CHK(err); +00098 err = lbm_src_topic_attr_str_setopt(src_attr, +00099 "transport_source_side_filtering_behavior", "inclusion"); +00100 EX_LBM_CHK(err); +00101 err = lbm_src_topic_alloc(&lbm_topic, client->ctx, client_resp_name, src_attr); +00102 EX_LBM_CHK(err); +00103 /* The following create can fail if a new client joins with the same +00104 * response topic name as an existing client. Should handle this cleanly. */ +00105 err = lbm_src_create(&client->resp_src, client->ctx, lbm_topic, +00106 NULL, NULL, NULL); +00107 if (err) { +00108 printf("Source '%s' failed; %s\n", client_resp_name, lbm_errmsg()); +00109 } +00110 else { +00111 client->state = 1; +00112 client->topic_name = strdup(client_resp_name); +00113 NULL_CHK(client->topic_name); +00114 printf("Source '%s' created\n", client->topic_name); +00115 } +00116 +00117 err = lbm_src_topic_attr_delete(src_attr); +00118 EX_LBM_CHK(err); +00119 } +00120 } /* handle_register */ ++ + + +The response source is created in a special way. + It is an LBT-RU transport type, with a fixed port number (the choice + of 12070 was arbitrary). + This means that all clients' sources are mapped to the same LBT-RU + transport session.
+ + ++00094 err = lbm_src_topic_attr_str_setopt(src_attr, "transport", "lbt-ru"); +00095 EX_LBM_CHK(err); +00096 err = lbm_src_topic_attr_str_setopt(src_attr, "transport_lbtru_port", "12070"); +00097 EX_LBM_CHK(err); ++ + + +To prevent each client's responses from being sent to all clients, + source-side filtering is enabled.
+ + ++00098 err = lbm_src_topic_attr_str_setopt(src_attr, +00099 "transport_source_side_filtering_behavior", "inclusion"); +00100 EX_LBM_CHK(err); ++ + + +On successful source creation, the client state is filled in. + But no reply is sent to the client. + This is because the client has not yet had a chance to discover and + join the new source, so any message sent at this point would not + be delivered.
+ + ++00111 client->state = 1; +00112 client->topic_name = strdup(client_resp_name); +00113 NULL_CHK(client->topic_name); +00114 printf("Source '%s' created\n", client->topic_name); ++ + + +The server could set some kind of timer to send its reply, but + to simplify this code, we just wait for the client to retry. + When the next registration request comes in, we send the OK + message. + Thus, it will always take at least 2 tries to register.
+ + ++00081 if (client->state == 1) { +00082 printf("Source '%s' re-confirmed\n", client->topic_name); +00083 /* Reply to client. */ +00084 err = lbm_src_send(client->resp_src, "rOK", 4, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); +00085 EX_LBM_CHK(err); +00086 } ++ + + +Request/Response
+ +This example does not contain the code necessary to associate responses + with their requests. + However, the simple protocol was designed to allow this to be added. + A request message consists of an 8-ascii-byte header followed by the + application message content. + The first byte of the header is the character 'R' to indicate a request + message. + The other 7 bytes are currently just set to ascii '0' characters, but + could be used as a request ID. + When the server responds to requests, it uses the same header it + received, so the client can maintain a table of outstanding requests. + This logic is not included in this example.
+ +Request: Client Side
+ +In this example, the send buffer for requests is declared as an + arbitrary large buffer. + The header is initialized once.
+ + ++00183 char send_buf[500]; +00184 req_hdr_t *req_hdr = (req_hdr_t *)send_buf; +00185 +00186 memset((char *)req_hdr, '0', sizeof(req_hdr_t)); +00187 req_hdr->data[0] = 'R'; ++ + + +For this simple example, 5 requests are sent.
+ + ++00189 for (i = 0; i < 5; i++) { +00190 /* The application builds a request into <tt>request_msg</tt>. */ +00191 char request_msg[257]; +00192 sprintf(request_msg, "%s.%d", response_topic_name, i); +00193 +00194 /* The application message is copied in after the header. */ +00195 strcpy(&send_buf[sizeof(req_hdr_t)], request_msg); +00196 err = lbm_src_send(server.src, send_buf, strlen(send_buf) + 1, +00197 LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); +00198 EX_LBM_CHK(err); +00199 MSLEEP(1000); +00200 } ++ + + +Response: Server Side
+ +When the server receives the request, it sends a response.
+ + ++00162 /* Request message. */ +00163 else if (msg->len >= sizeof(req_hdr_t) && msg->data[0] == 'R') { +00164 req_hdr_t req_hdr; +00165 memcpy((char *)&req_hdr, msg->data, sizeof(req_hdr_t)); +00166 +00167 handle_req(client, &req_hdr, &msg->data[sizeof(req_hdr_t)], +00168 msg->len - sizeof(req_hdr_t)); +00169 } ++ + +. . .
+ ++00123 void handle_req(client_t *client, req_hdr_t *req_hdr, const char *req_msg, size_t len) +00124 { +00125 int err; +00126 +00127 /* This work should probably be passed to a separate worker thread, but +00128 * I'll do it here to simplify the code. */ +00129 +00130 /* Responses copy the header from the request. */ +00131 memcpy(&client->send_buf[0], (char *)req_hdr, sizeof(req_hdr_t)); +00132 /* Response message is put after the header. */ +00133 char *response_msg = &client->send_buf[sizeof(req_hdr_t)]; +00134 +00135 /* Do the work of the request and put the response in response_msg. +00136 * (For this sample, just echo back the request.) */ +00137 strcpy(response_msg, req_msg); +00138 +00139 /* Reply to client. */ +00140 err = lbm_src_send(client->resp_src, client->send_buf, +00141 strlen(client->send_buf) + 1, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); +00142 EX_LBM_CHK(err); +00143 printf("sent response to '%s'.\n", client->topic_name); +00144 } /* handle_req */ ++ + + + + diff --git a/ss_frag/README.txt b/ss_frag/README.txt new file mode 100644 index 0000000..edea64d --- /dev/null +++ b/ss_frag/README.txt @@ -0,0 +1,3 @@ +Summary=A sample application that demonstrates application-level message fragmentation/reassembly for Smart Source. + +Description= diff --git a/ss_frag/c/blank.html b/ss_frag/c/blank.html new file mode 100644 index 0000000..0841bfc --- /dev/null +++ b/ss_frag/c/blank.html @@ -0,0 +1 @@ +Click a source line number to see the line in context. diff --git a/ss_frag/c/index.html b/ss_frag/c/index.html new file mode 100644 index 0000000..a36528e --- /dev/null +++ b/ss_frag/c/index.html @@ -0,0 +1,6 @@ + + + diff --git a/ss_frag/c/ss_frag.c b/ss_frag/c/ss_frag.c new file mode 100644 index 0000000..408d31c --- /dev/null +++ b/ss_frag/c/ss_frag.c @@ -0,0 +1,459 @@ +/* ss_frag.c - see http://ultramessaging.github.io/UMExamples/ss_frag/c/index.html + * + * Copyright (c) 2005-2018 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + +#include+#include + +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define SLEEP(s) Sleep((s)*1000) +#else +/* Unix-only includes */ +#include +#include +#define SLEEP(s) sleep(s) +#endif + +#include + + +/* Application structure associated with a smart source. + */ +typedef struct { + lbm_context_t *ctx; + lbm_ssrc_t *ssrc; + char *msgbuf_plain; + char *msgbuf_props; + int max_msg_len; + lbm_ssrc_send_ex_info_t info_prop; + lbm_uint32_t int_value_array[2]; + char *key_ptr_array[2]; + char remain_key[8]; +} smart_source_t; + + +/* Receiver state used to reassemble fragmented messages. Used as per-source + * clientd. + */ +typedef struct { + int collecting; /* 1=true, 0=false. */ + char *reassem_buf; + size_t reassem_buf_size; + size_t message_len; /* Size of message being reassembled. */ + size_t offset; /* Current offset within reassem_buf[]. */ + long num_bad_frags; /* Statistic: bad fragemnts. */ +} rcv_state_t; + + +/* + * Simple lbm error handling. + */ + +/* Macro to approximate the basename() function. */ +#define BASENAME(_p) ((strrchr(_p, '/') == NULL) ? (_p) : (strrchr(_p, '/')+1)) + +/* Pass in an LBM return status. If not success, print error and abort. */ +#define LBM_ERR(_e) do {\ + if ((_e) != LBM_OK) {\ + printf("LBM_ERR: at %s:%d (%s)\n",\ + BASENAME(__FILE__), __LINE__, lbm_errmsg());\ + fflush(stdout);\ + abort();\ + }\ +} while (0) + +/* Print error and abort. */ +#define ERR(_s) do {\ + printf("ERR: at %s:%d (%s)\n",\ + BASENAME(__FILE__), __LINE__, _s);\ + fflush(stdout);\ + abort();\ +} while (0) + + +/* Called by receiver callback when a received messager has the "Remain" + * message property, indicating a fragmented message. + */ +void handle_msg_frag(lbm_msg_t *msg, rcv_state_t *rcv_state, + lbm_int32_t remaining) +{ + size_t tot_len; + + if (rcv_state->collecting) { + /* Make sure the fragment is OK. */ + if (remaining >= 0 && + (rcv_state->message_len == (rcv_state->offset + msg->len + remaining))) + { + /* Collect the fragment. */ + memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, + msg->len); + rcv_state->offset += msg->len; + + if (remaining == 0) { /* No more, deliver the data. */ + printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", + rcv_state->reassem_buf[0], + rcv_state->message_len - 1, + rcv_state->reassem_buf[rcv_state->message_len - 1]); + + /* No longer collecting. */ + rcv_state->collecting = 0; + } + } /* if fragment OK */ + else { /* fragment is not ok. */ + /* Bad fragment (should never happen). */ + printf("Collect error: bad fragment, remaining=%d, offset=%ld, len=%lu, message_len=%ld\n", remaining, rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->num_bad_frags ++; + + /* Error, stop collecting. */ + rcv_state->collecting = 0; + } + } + + else { /* not collecting */ + /* Not collecting a fragmented message, is this message first frag? */ + if (remaining < 0) { + /* First fragment. */ + rcv_state->collecting = 1; + rcv_state->offset = 0; + rcv_state->message_len = msg->len + (- remaining); + /* Expand buffer if necessary. */ + if (rcv_state->message_len > rcv_state->reassem_buf_size) { + rcv_state->reassem_buf_size = rcv_state->message_len; + rcv_state->reassem_buf = (char *)realloc(rcv_state->reassem_buf, + rcv_state->reassem_buf_size); + } + + /* Collect data. */ + memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, msg->len); + rcv_state->offset += msg->len; + } /* remaining < 0 */ + else { /* Found middle frag without a first frag; discard. */ + /* Probably joined stream in middle of message. */ + printf("info: found middle frag but not collecting, remaining=%d, offset=%ld, len=%lu, message_len=%ld\n", remaining, rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->num_bad_frags ++; + } + } /* not collecting */ +} /* handle_msg_frag */ + + +/* UM receiver callback. + */ +int msg_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +{ + rcv_state_t *rcv_state = (rcv_state_t *)msg->source_clientd; + int err; + + switch (msg->type) { + case LBM_MSG_DATA: + if (msg->properties == NULL) { + /* Fast path (not part of a fragmented messqge). */ + if (rcv_state->collecting) { + /* Error, non-frag, but state is collecting (should never happen). */ + printf("Collect error non-frag, offset=%ld, len=%lu, message_len=%ld\n", rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->collecting = 0; + rcv_state->num_bad_frags ++; + } + + /* Deliver data message. */ + printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", + msg->data[0], + msg->len - 1, + msg->data[msg->len - 1]); + } + else { /* msg properties */ + lbm_int32_t remaining; + size_t prop_size = sizeof(remaining); + int prop_type = LBM_MSG_PROPERTY_INT; + + /* Found property, is it for fragmentation? */ + err = lbm_msg_properties_get(msg->properties, "Remain", + &remaining, &prop_type, &prop_size); + if (err == LBM_OK) { + handle_msg_frag(msg, rcv_state, remaining); + } + else { + printf("handle messages with other properties.\n"); + } + } /* msg properties not null */ + break; + + case LBM_MSG_UNRECOVERABLE_LOSS: + case LBM_MSG_UNRECOVERABLE_LOSS_BURST: + if (rcv_state->collecting) { + /* Stop collecting after error. */ + rcv_state->collecting = 0; + rcv_state->num_bad_frags ++; + } + + default: + printf("Non data receiver event, type=%d\n", msg->type); + } /* switch msg type */ + + return 0; +} /* msg_rcv_cb */ + + +/* Callback when a receiver delivery controller is created for a new source. */ +void *per_src_clientd_create(const char *source_name, void *clientd) +{ + rcv_state_t *rcv_state; + + rcv_state = (rcv_state_t *)malloc(sizeof(rcv_state_t)); + + rcv_state->reassem_buf_size = 8192; + rcv_state->reassem_buf = (char *)malloc(rcv_state->reassem_buf_size); + rcv_state->collecting = 0; + rcv_state->num_bad_frags = 0; + + return rcv_state; +} /* per_src_clientd_create */ + + +/* Callback when a receiver delivery controller for an ex-source is deleted. */ +int per_src_clientd_delete(const char *source_name, void *clientd, + void *src_clientd) +{ + rcv_state_t *rcv_state = (rcv_state_t *)src_clientd; + + if (rcv_state->collecting) { + /* Error, state is collecting. */ + printf("Collect error, incomplete fragmented message, offset=%ld, message_len=%ld\n", rcv_state->offset, rcv_state->message_len); + } + if (rcv_state->num_bad_frags > 0) { + printf("Number of bad fragments=%ld\n", rcv_state->num_bad_frags); + } + + free(rcv_state->reassem_buf); + free(rcv_state); + + return 0; +} /* per_src_clientd_delete */ + + +/* Create a SmartSource, and init associated state. + */ +void smart_source_init(smart_source_t *smart_source, lbm_context_t *ctx, + char *topic) +{ + lbm_topic_t *lbm_topic = NULL; + lbm_src_topic_attr_t *src_tattr = NULL; + int prop_count; + size_t opt_len; + int err; + + smart_source->ctx = ctx; + + err = lbm_src_topic_attr_create(&src_tattr); + LBM_ERR(err); + + /* Make sure user's config allows at least 1 msg property. */ + opt_len = sizeof(prop_count); + err = lbm_src_topic_attr_getopt(src_tattr, + "smart_src_message_property_int_count", &prop_count, &opt_len); + LBM_ERR(err); + if (prop_count == 0) { + /* No props configured, add one. */ + prop_count = 1; + opt_len = sizeof(prop_count); + err = lbm_src_topic_attr_setopt(src_tattr, + "smart_src_message_property_int_count", &prop_count, opt_len); + LBM_ERR(err); + } + + /* Find out the user's config for max message length. */ + opt_len = sizeof(smart_source->max_msg_len); + err = lbm_src_topic_attr_getopt(src_tattr, + "smart_src_max_message_length", &(smart_source->max_msg_len), &opt_len); + LBM_ERR(err); + + err = lbm_src_topic_alloc(&lbm_topic, ctx, topic, src_tattr); + LBM_ERR(err); + + err = lbm_ssrc_create(&(smart_source->ssrc), ctx, lbm_topic, NULL, NULL, + NULL); + LBM_ERR(err); + + err = lbm_src_topic_attr_delete(src_tattr); + LBM_ERR(err); + + err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_plain, 0); + LBM_ERR(err); + err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_props, 0); + LBM_ERR(err); + + /* Set up message property. */ + smart_source->info_prop.flags = LBM_SSRC_SEND_EX_FLAG_PROPERTIES; + smart_source->info_prop.mprop_int_cnt = 1; + smart_source->info_prop.mprop_int_vals = smart_source->int_value_array; + smart_source->info_prop.mprop_int_keys = &smart_source->key_ptr_array[0]; + smart_source->key_ptr_array[0] = smart_source->remain_key; + strncpy(smart_source->remain_key, "Remain", sizeof(smart_source->remain_key)); +} /* smart_source_init */ + + +/* Send a message, fragmenting it if necessary. + */ +void smart_source_send(smart_source_t *smart_source, char *buf, size_t len, + int flags) +{ + int err; + + if (len <= smart_source->max_msg_len) { + /* Message fits in one buffer, send it. */ + memcpy(smart_source->msgbuf_plain, buf, len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_plain, + len, 0, NULL); + LBM_ERR(err); + } + + else { /* Message does not fit in one buffer */ + int offset; + int remaining; + int this_len; + + /* Fragment message. */ + remaining = len; + offset = 0; + + this_len = smart_source->max_msg_len; + remaining -= this_len; + /* Indicate first fragment with negative remainer. */ + smart_source->int_value_array[0] = - remaining; + memcpy(smart_source->msgbuf_props, &buf[offset], this_len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, + this_len, 0, &(smart_source->info_prop)); + LBM_ERR(err); + offset += this_len; + + /* From now on, need to update the properties. */ + smart_source->info_prop.flags |= LBM_SSRC_SEND_EX_FLAG_UPDATE_PROPERTY_VALUES; + + /* Send rest of fragments. */ + while (remaining > 0) { + if (remaining > smart_source->max_msg_len) { + this_len = smart_source->max_msg_len; + } + else { + this_len = remaining; + } + remaining -= this_len; + smart_source->int_value_array[0] = remaining; + memcpy(smart_source->msgbuf_props, &buf[offset], this_len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, + this_len, 0, &(smart_source->info_prop)); + + offset += this_len; + } /* while */ + } +} /* smart_source_send */ + + +int main(int argc, char **argv) { + lbm_context_t *rctx = NULL; + lbm_context_t *sctx = NULL; + lbm_rcv_topic_attr_t *rcv_attr = NULL; + lbm_rcv_src_notification_func_t src_notif_func; /* config option */ + lbm_topic_t *lbm_topic = NULL; + lbm_rcv_t *rcv; + smart_source_t smart_source; + char *send_buff; + int err; + + err = lbm_config("test.cfg"); + LBM_ERR(err); + + /* Create a pair of contexts, one for publisher, the other for subscriber. + */ + + err = lbm_context_create(&rctx, NULL, NULL, NULL); + LBM_ERR(err); + + err = lbm_context_create(&sctx, NULL, NULL, NULL); + LBM_ERR(err); + + + /* Create receiver. + */ + + err = lbm_rcv_topic_attr_create(&rcv_attr); + LBM_ERR(err); + + src_notif_func.create_func = per_src_clientd_create; + src_notif_func.delete_func = per_src_clientd_delete; + src_notif_func.clientd = NULL; /* Or your own state structure. */ + err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", + &src_notif_func, sizeof(src_notif_func)); + LBM_ERR(err); + + err = lbm_rcv_topic_lookup(&lbm_topic, rctx, "topic_1", rcv_attr); + LBM_ERR(err); + + err = lbm_rcv_create(&rcv, rctx, lbm_topic, msg_rcv_cb, NULL, NULL); + LBM_ERR(err); + + + /* Create source. + */ + smart_source_init(&smart_source, sctx, "topic_1"); + + send_buff = (char *)malloc(70000); /* Bigger than 64k, for fun. */ + + SLEEP(1); /* For topic res. */ + + + /* Send messages. + */ + + send_buff[0] = 1; send_buff[999] = 1; + smart_source_send(&smart_source, send_buff, 1000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 2; send_buff[4999] = 2; + smart_source_send(&smart_source, send_buff, 5000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 3; send_buff[19999] = 3; + smart_source_send(&smart_source, send_buff, 20000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 4; send_buff[99] = 4; + smart_source_send(&smart_source, send_buff, 100, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 5; send_buff[69999] = 5; + smart_source_send(&smart_source, send_buff, 70000, LBM_MSG_FLUSH); + SLEEP(1); + + + /* Shut down. + */ + + free(send_buff); + + (void)lbm_ssrc_delete(smart_source.ssrc); + (void)lbm_rcv_delete(rcv); + + (void)lbm_context_delete(rctx); + (void)lbm_context_delete(sctx); + + return 0; +} /* main */ diff --git a/ss_frag/c/ss_frag.sldoc b/ss_frag/c/ss_frag.sldoc new file mode 100644 index 0000000..100c0c5 --- /dev/null +++ b/ss_frag/c/ss_frag.sldoc @@ -0,0 +1,95 @@ + + + + Smart Source Message Fragmentation + + + =semlit,include,../intro.sldoc= +There is one program source file and one test configuration file:
++
+ +- =semlit,srcfile,ss_frag_c.slsrc,ss_frag.c= + - (right-click and save as "ss_frag.c") main program.
+=semlit,initialsource,ss_frag_c.slsrc.html= +- =semlit,srcfile,test_cfg.txt,test.cfg= + - (right-click and save as "test.cfg") main program.
+The ss_frag.c file contains:
++
+- Source-side code (fragments messages),
+- Receive-side code (reassembles messages),
+- Simple demonstration code.
+Source-Side Code
+At the heart of the source-side code is the function + smart_source_send():
+ =semlit,insert,send_funct= +CLICK ON A LINE NUBMER TO SEE THE CODE ON THE RIGHT IN CONTEXT!
+This function first checks to see if the application message is + small enough to fit in a single message. If so, it sends the + message without any message properties.
+ =semlit,insert,send_check= +For application messages that are too big, they need to be + fragmented. The "Remain" message property is set to negative + of the remaining size after this fragment is sent.
+ =semlit,insert,send_first= +Subsequent fragments are sent, chunk at a time, with + a positive "Remain" property.
+ =semlit,insert,send_rest= +Send Buffers
+For efficiency and simplicity, two Smart Source send buffers + are used to send messages: msgbuf_plain for small messages + with no properties, and msgbuf_props for large fragmented + messages that have properties. They are initialized in + smart_source_init().
+ =semlit,insert,send_buffs= +The message property is also initialized.
+ =semlit,insert,send_props= +The source-side code needs to know what the size threshold is for + fragmented messages. It determines this by creating a source + attribute object, which inherets the user's configuration.
+ =semlit,insert,send_attr= +Then, the configured value for the option + smart_src_max_message_length (source) + is read.
+ =semlit,insert,send_size= +There is also a sanity check to make sure the user configured a + message property.
+ =semlit,insert,send_conf_prop= +Receiver-Side Code
+At the heart of the receiver-side code is the receiver application + callback function smart_source_send():
+ =semlit,insert,rcv_cb= +If there is no message property with the message, it is a small + (non-fragmented) message, and can be delivered. + It does a sanity check first to make sure there isn't a fragmented + message in-progress.
+ =semlit,insert,rcv_no_prop= +Otherwise, there is a property, which we make sure is "Remain". + =semlit,insert,rcv_tst_prop= +
Once the message is known to be a fragment, it is passed to the + function handle_msg_frag() for reassembly. + This function has two states it can be in: collecting (in the middle + of a fragmented message), or not collecting (waiting for a negative + "Remain" property to indicate the start of a fragmented message).
+If it is collecting, the newly-received message is validated to make + sure it is the expected next fragment.
+ =semlit,insert,rcv_chk_frag= +Once validated, the message content is collected. + If this is the last fragment in the message ("Remain"==0) then the + reassembled message is delivered.
+ =semlit,insert,rcv_collect= +First Fragment Processing
+If handle_msg_frag() is called and the receiver state is + not collecting, then the fragment should be the first + fragment of a large message ("Remain" negative).
+ =semlit,insert,rcv_first_frag= +Start the collection state.
+ =semlit,insert,rcv_start_collect= +To keep the algorithm general, if the fragmented message is larger + than the currently-allocated reassembly buffer, expand it.
+ =semlit,insert,rcv_expand= +Finally, collect the first fragment's data.
+ =semlit,insert,rcv_collect_first= + + diff --git a/ss_frag/c/ss_frag.sldoc.html b/ss_frag/c/ss_frag.sldoc.html new file mode 100644 index 0000000..09ab8db --- /dev/null +++ b/ss_frag/c/ss_frag.sldoc.html @@ -0,0 +1,352 @@ + + + +Smart Source Message Fragmentation + + + Example index +Smart Source Message Fragmentation
+Ultra Messaging has a feature called + Smart Sources + which provides lower average latency and much lower latency + variation (jitter) than traditional UM sources. + Smart Sources are able to deliver these benefits by trading off reduced + flexibility for simplicity, especially simplicity in memory usage.
+One area of reduced flexibility is related to message sizes. + To avoid dynamic memory allocation/deallocation, Smart Sources require + the user to configure the maximum expected message size. + Also, Smart Sources do not support fragmentation and reassembly of + messages larger than the maximum datagram size. + An application message must fit in a single datagram. + Finally, users of kernel bypass TCP/IP stacks (like Solarflare's Onload) + pay a heavy penalty if IP fragmentation is performed by the kernel. + These users typically want to keep each datagram at or below the + NIC's MTU size (typically 1500 bytes).
+However, many applications have a fairly small average message size, + but occasionally need to send messages that are much larger. + If that worst-case large message size is larger than an MTU, + it cannot be efficiently sent using Onload or other kernel bypass stacks.
+Also, even if IP fragmentation is not a problem, + a Smart Sources pre-allocates its retransmission buffers based on the + worst-case message size. + For applications that normally send small messages but occasionally + need to send very large ones, + this can lead to a significant memory footprint.
+One solution to these problems is for an application to configure Smart + Source for small messages, and perform message fragmentation and + reassembly at the application level. + This example program does just that.
+High-Level Design
+An integer message property with key name "Remain" is used to manage + message fragmentation and reassembly. + Small messages may be sent without a property. + Messages which exceed a configured threshold will be sent in "chunks", + with a message property providing the information needed by the + receiver to reassemble the chunks.
+When the application wants to send a message larger than + [smart_src_max_message_length (source)](https://ultramessaging.github.io/currdoc/doc/Config/grpsmartsource.html#smartsrcmaxmessagelengthsource), + the first fragment is sent with the "Remain" property is a negative + number representing the number of bytes that still need to be sent + (not counting the content of that first message). + Each subsequent message fragment sent has the "Remain" property as + a positive number of the number of bytes remaining + after that message.
+For example, if smart_src_max_message_length is set to 1400 and a + 5000 byte message is sent, 4 UM messages will be sent. + Here are the message lengths and values for the "Remain" property:
++
- length=1400, Remain=-3600
+- length=1400, Remain=2200
+- length=1400, Remain=800
+- length=800, Remain=0
+When the receiver sees Remain=0, it can deliver the reassembled message.
+ +There is one program source file and one test configuration file:
++
+ +- ss_frag.c + - (right-click and save as "ss_frag.c") main program.
+ +- test.cfg + - (right-click and save as "test.cfg") main program.
+The ss_frag.c file contains:
++
+- Source-side code (fragments messages),
+- Receive-side code (reassembles messages),
+- Simple demonstration code.
+Source-Side Code
+At the heart of the source-side code is the function + smart_source_send():
+ ++00313 /* Send a message, fragmenting it if necessary. +00314 */ +00315 void smart_source_send(smart_source_t *smart_source, char *buf, size_t len, +00316 int flags) +00317 { ++ + +CLICK ON A LINE NUBMER TO SEE THE CODE ON THE RIGHT IN CONTEXT!
+This function first checks to see if the application message is + small enough to fit in a single message. If so, it sends the + message without any message properties.
+ ++00320 if (len <= smart_source->max_msg_len) { +00321 /* Message fits in one buffer, send it. */ +00322 memcpy(smart_source->msgbuf_plain, buf, len); +00323 err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_plain, +00324 len, 0, NULL); +00325 LBM_ERR(err); +00326 } ++ + +For application messages that are too big, they need to be + fragmented. The "Remain" message property is set to negative + of the remaining size after this fragment is sent.
+ ++00337 this_len = smart_source->max_msg_len; +00338 remaining -= this_len; +00339 /* Indicate first fragment with negative remainer. */ +00340 smart_source->int_value_array[0] = - remaining; +00341 memcpy(smart_source->msgbuf_props, &buf[offset], this_len); +00342 err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, +00343 this_len, 0, &(smart_source->info_prop)); +00344 LBM_ERR(err); +00345 offset += this_len; ++ + +Subsequent fragments are sent, chunk at a time, with + a positive "Remain" property.
+ ++00350 /* Send rest of fragments. */ +00351 while (remaining > 0) { +00352 if (remaining > smart_source->max_msg_len) { +00353 this_len = smart_source->max_msg_len; +00354 } +00355 else { +00356 this_len = remaining; +00357 } +00358 remaining -= this_len; +00359 smart_source->int_value_array[0] = remaining; +00360 memcpy(smart_source->msgbuf_props, &buf[offset], this_len); +00361 err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, +00362 this_len, 0, &(smart_source->info_prop)); +00363 +00364 offset += this_len; +00365 } /* while */ ++ + +Send Buffers
+For efficiency and simplicity, two Smart Source send buffers + are used to send messages: msgbuf_plain for small messages + with no properties, and msgbuf_props for large fragmented + messages that have properties. They are initialized in + smart_source_init().
+ ++00298 err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_plain, 0); +00299 LBM_ERR(err); +00300 err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_props, 0); +00301 LBM_ERR(err); ++ + +The message property is also initialized.
+ ++00303 /* Set up message property. */ +00304 smart_source->info_prop.flags = LBM_SSRC_SEND_EX_FLAG_PROPERTIES; +00305 smart_source->info_prop.mprop_int_cnt = 1; +00306 smart_source->info_prop.mprop_int_vals = smart_source->int_value_array; +00307 smart_source->info_prop.mprop_int_keys = &smart_source->key_ptr_array[0]; +00308 smart_source->key_ptr_array[0] = smart_source->remain_key; +00309 strncpy(smart_source->remain_key, "Remain", sizeof(smart_source->remain_key)); ++ + +The source-side code needs to know what the size threshold is for + fragmented messages. It determines this by creating a source + attribute object, which inherets the user's configuration.
+ ++00265 err = lbm_src_topic_attr_create(&src_tattr); +00266 LBM_ERR(err); ++ + +Then, the configured value for the option + smart_src_max_message_length (source) + is read.
+ ++00282 /* Find out the user's config for max message length. */ +00283 opt_len = sizeof(smart_source->max_msg_len); +00284 err = lbm_src_topic_attr_getopt(src_tattr, +00285 "smart_src_max_message_length", &(smart_source->max_msg_len), &opt_len); +00286 LBM_ERR(err); ++ + +There is also a sanity check to make sure the user configured a + message property.
+ ++00268 /* Make sure user's config allows at least 1 msg property. */ +00269 opt_len = sizeof(prop_count); +00270 err = lbm_src_topic_attr_getopt(src_tattr, +00271 "smart_src_message_property_int_count", &prop_count, &opt_len); +00272 LBM_ERR(err); +00273 if (prop_count == 0) { +00274 /* No props configured, add one. */ +00275 prop_count = 1; +00276 opt_len = sizeof(prop_count); +00277 err = lbm_src_topic_attr_setopt(src_tattr, +00278 "smart_src_message_property_int_count", &prop_count, opt_len); +00279 LBM_ERR(err); +00280 } ++ + +Receiver-Side Code
+At the heart of the receiver-side code is the receiver application + callback function smart_source_send():
+ ++00158 /* UM receiver callback. +00159 */ +00160 int msg_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +00161 { ++ + +If there is no message property with the message, it is a small + (non-fragmented) message, and can be delivered. + It does a sanity check first to make sure there isn't a fragmented + message in-progress.
+ ++00167 if (msg->properties == NULL) { +00168 /* Fast path (not part of a fragmented messqge). */ +00169 if (rcv_state->collecting) { +00170 /* Error, non-frag, but state is collecting (should never happen). */ +00171 printf("Collect error non-frag, offset=%ld, len=%lu, message_len=%ld\n", rcv_state->offset, msg->len, rcv_state->message_len); +00172 rcv_state->collecting = 0; +00173 rcv_state->num_bad_frags ++; +00174 } +00175 +00176 /* Deliver data message. */ +00177 printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", +00178 msg->data[0], +00179 msg->len - 1, +00180 msg->data[msg->len - 1]); +00181 } ++ + +Otherwise, there is a property, which we make sure is "Remain". + +
+00187 /* Found property, is it for fragmentation? */ +00188 err = lbm_msg_properties_get(msg->properties, "Remain", +00189 &remaining, &prop_type, &prop_size); +00190 if (err == LBM_OK) { +00191 handle_msg_frag(msg, rcv_state, remaining); +00192 } ++ + +Once the message is known to be a fragment, it is passed to the + function handle_msg_frag() for reassembly. + This function has two states it can be in: collecting (in the middle + of a fragmented message), or not collecting (waiting for a negative + "Remain" property to indicate the start of a fragmented message).
+If it is collecting, the newly-received message is validated to make + sure it is the expected next fragment.
+ ++00101 if (rcv_state->collecting) { +00102 /* Make sure the fragment is OK. */ +00103 if (remaining >= 0 && +00104 (rcv_state->message_len == (rcv_state->offset + msg->len + remaining))) +00105 { ++ + +Once validated, the message content is collected. + If this is the last fragment in the message ("Remain"==0) then the + reassembled message is delivered.
+ ++00106 /* Collect the fragment. */ +00107 memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, +00108 msg->len); +00109 rcv_state->offset += msg->len; +00110 +00111 if (remaining == 0) { /* No more, deliver the data. */ +00112 printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", +00113 rcv_state->reassem_buf[0], +00114 rcv_state->message_len - 1, +00115 rcv_state->reassem_buf[rcv_state->message_len - 1]); +00116 +00117 /* No longer collecting. */ +00118 rcv_state->collecting = 0; +00119 } ++ + +First Fragment Processing
+If handle_msg_frag() is called and the receiver state is + not collecting, then the fragment should be the first + fragment of a large message ("Remain" negative).
+ ++00131 else { /* not collecting */ +00132 /* Not collecting a fragmented message, is this message first frag? */ +00133 if (remaining < 0) { +00134 /* First fragment. */ ++ + +Start the collection state.
+ ++00135 rcv_state->collecting = 1; +00136 rcv_state->offset = 0; +00137 rcv_state->message_len = msg->len + (- remaining); ++ + +To keep the algorithm general, if the fragmented message is larger + than the currently-allocated reassembly buffer, expand it.
+ ++00138 /* Expand buffer if necessary. */ +00139 if (rcv_state->message_len > rcv_state->reassem_buf_size) { +00140 rcv_state->reassem_buf_size = rcv_state->message_len; +00141 rcv_state->reassem_buf = (char *)realloc(rcv_state->reassem_buf, +00142 rcv_state->reassem_buf_size); +00143 } ++ + +Finally, collect the first fragment's data.
+ ++00145 /* Collect data. */ +00146 memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, msg->len); +00147 rcv_state->offset += msg->len; ++ + + + + diff --git a/ss_frag/c/ss_frag_c.slsrc b/ss_frag/c/ss_frag_c.slsrc new file mode 100644 index 0000000..f773582 --- /dev/null +++ b/ss_frag/c/ss_frag_c.slsrc @@ -0,0 +1,495 @@ +/* ss_frag.c - see http://ultramessaging.github.io/UMExamples/ss_frag/c/index.html + * + * Copyright (c) 2005-2018 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + +#include+#include + +#if defined(_MSC_VER) +/* Windows-only includes */ +#include +#define SLEEP(s) Sleep((s)*1000) +#else +/* Unix-only includes */ +#include +#include +#define SLEEP(s) sleep(s) +#endif + +#include + + +/* Application structure associated with a smart source. + */ +typedef struct { + lbm_context_t *ctx; + lbm_ssrc_t *ssrc; + char *msgbuf_plain; + char *msgbuf_props; + int max_msg_len; + lbm_ssrc_send_ex_info_t info_prop; + lbm_uint32_t int_value_array[2]; + char *key_ptr_array[2]; + char remain_key[8]; +} smart_source_t; + + +/* Receiver state used to reassemble fragmented messages. Used as per-source + * clientd. + */ +typedef struct { + int collecting; /* 1=true, 0=false. */ + char *reassem_buf; + size_t reassem_buf_size; + size_t message_len; /* Size of message being reassembled. */ + size_t offset; /* Current offset within reassem_buf[]. */ + long num_bad_frags; /* Statistic: bad fragemnts. */ +} rcv_state_t; + + +/* + * Simple lbm error handling. + */ + +/* Macro to approximate the basename() function. */ +#define BASENAME(_p) ((strrchr(_p, '/') == NULL) ? (_p) : (strrchr(_p, '/')+1)) + +/* Pass in an LBM return status. If not success, print error and abort. */ +#define LBM_ERR(_e) do {\ + if ((_e) != LBM_OK) {\ + printf("LBM_ERR: at %s:%d (%s)\n",\ + BASENAME(__FILE__), __LINE__, lbm_errmsg());\ + fflush(stdout);\ + abort();\ + }\ +} while (0) + +/* Print error and abort. */ +#define ERR(_s) do {\ + printf("ERR: at %s:%d (%s)\n",\ + BASENAME(__FILE__), __LINE__, _s);\ + fflush(stdout);\ + abort();\ +} while (0) + + +/* Called by receiver callback when a received messager has the "Remain" + * message property, indicating a fragmented message. + */ +void handle_msg_frag(lbm_msg_t *msg, rcv_state_t *rcv_state, + lbm_int32_t remaining) +{ + size_t tot_len; + +/* =semlit,block,rcv_chk_frag=*/ + if (rcv_state->collecting) { + /* Make sure the fragment is OK. */ + if (remaining >= 0 && + (rcv_state->message_len == (rcv_state->offset + msg->len + remaining))) + { +/* =semlit,endblock,rcv_chk_frag=*/ +/* =semlit,block,rcv_collect=*/ + /* Collect the fragment. */ + memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, + msg->len); + rcv_state->offset += msg->len; + + if (remaining == 0) { /* No more, deliver the data. */ + printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", + rcv_state->reassem_buf[0], + rcv_state->message_len - 1, + rcv_state->reassem_buf[rcv_state->message_len - 1]); + + /* No longer collecting. */ + rcv_state->collecting = 0; + } +/* =semlit,endblock,rcv_collect=*/ + } /* if fragment OK */ + else { /* fragment is not ok. */ + /* Bad fragment (should never happen). */ + printf("Collect error: bad fragment, remaining=%d, offset=%ld, len=%lu, message_len=%ld\n", remaining, rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->num_bad_frags ++; + + /* Error, stop collecting. */ + rcv_state->collecting = 0; + } + } + +/* =semlit,block,rcv_first_frag=*/ + else { /* not collecting */ + /* Not collecting a fragmented message, is this message first frag? */ + if (remaining < 0) { + /* First fragment. */ +/* =semlit,endblock,rcv_first_frag=*/ +/* =semlit,block,rcv_start_collect=*/ + rcv_state->collecting = 1; + rcv_state->offset = 0; + rcv_state->message_len = msg->len + (- remaining); +/* =semlit,endblock,rcv_start_collect=*/ +/* =semlit,block,rcv_expand=*/ + /* Expand buffer if necessary. */ + if (rcv_state->message_len > rcv_state->reassem_buf_size) { + rcv_state->reassem_buf_size = rcv_state->message_len; + rcv_state->reassem_buf = (char *)realloc(rcv_state->reassem_buf, + rcv_state->reassem_buf_size); + } +/* =semlit,endblock,rcv_expand=*/ + +/* =semlit,block,rcv_collect_first=*/ + /* Collect data. */ + memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, msg->len); + rcv_state->offset += msg->len; +/* =semlit,endblock,rcv_collect_first=*/ + } /* remaining < 0 */ + else { /* Found middle frag without a first frag; discard. */ + /* Probably joined stream in middle of message. */ + printf("info: found middle frag but not collecting, remaining=%d, offset=%ld, len=%lu, message_len=%ld\n", remaining, rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->num_bad_frags ++; + } + } /* not collecting */ +} /* handle_msg_frag */ + + +/* =semlit,block,rcv_cb=*/ +/* UM receiver callback. + */ +int msg_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) +{ +/* =semlit,endblock,rcv_cb=*/ + rcv_state_t *rcv_state = (rcv_state_t *)msg->source_clientd; + int err; + + switch (msg->type) { + case LBM_MSG_DATA: +/* =semlit,block,rcv_no_prop=*/ + if (msg->properties == NULL) { + /* Fast path (not part of a fragmented messqge). */ + if (rcv_state->collecting) { + /* Error, non-frag, but state is collecting (should never happen). */ + printf("Collect error non-frag, offset=%ld, len=%lu, message_len=%ld\n", rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->collecting = 0; + rcv_state->num_bad_frags ++; + } + + /* Deliver data message. */ + printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", + msg->data[0], + msg->len - 1, + msg->data[msg->len - 1]); + } +/* =semlit,endblock,rcv_no_prop=*/ + else { /* msg properties */ + lbm_int32_t remaining; + size_t prop_size = sizeof(remaining); + int prop_type = LBM_MSG_PROPERTY_INT; + +/* =semlit,block,rcv_tst_prop=*/ + /* Found property, is it for fragmentation? */ + err = lbm_msg_properties_get(msg->properties, "Remain", + &remaining, &prop_type, &prop_size); + if (err == LBM_OK) { + handle_msg_frag(msg, rcv_state, remaining); + } +/* =semlit,endblock,rcv_tst_prop=*/ + else { + printf("handle messages with other properties.\n"); + } + } /* msg properties not null */ + break; + + case LBM_MSG_UNRECOVERABLE_LOSS: + case LBM_MSG_UNRECOVERABLE_LOSS_BURST: + if (rcv_state->collecting) { + /* Stop collecting after error. */ + rcv_state->collecting = 0; + rcv_state->num_bad_frags ++; + } + + default: + printf("Non data receiver event, type=%d\n", msg->type); + } /* switch msg type */ + + return 0; +} /* msg_rcv_cb */ + + +/* Callback when a receiver delivery controller is created for a new source. */ +void *per_src_clientd_create(const char *source_name, void *clientd) +{ + rcv_state_t *rcv_state; + + rcv_state = (rcv_state_t *)malloc(sizeof(rcv_state_t)); + + rcv_state->reassem_buf_size = 8192; + rcv_state->reassem_buf = (char *)malloc(rcv_state->reassem_buf_size); + rcv_state->collecting = 0; + rcv_state->num_bad_frags = 0; + + return rcv_state; +} /* per_src_clientd_create */ + + +/* Callback when a receiver delivery controller for an ex-source is deleted. */ +int per_src_clientd_delete(const char *source_name, void *clientd, + void *src_clientd) +{ + rcv_state_t *rcv_state = (rcv_state_t *)src_clientd; + + if (rcv_state->collecting) { + /* Error, state is collecting. */ + printf("Collect error, incomplete fragmented message, offset=%ld, message_len=%ld\n", rcv_state->offset, rcv_state->message_len); + } + if (rcv_state->num_bad_frags > 0) { + printf("Number of bad fragments=%ld\n", rcv_state->num_bad_frags); + } + + free(rcv_state->reassem_buf); + free(rcv_state); + + return 0; +} /* per_src_clientd_delete */ + + +/* Create a SmartSource, and init associated state. + */ +void smart_source_init(smart_source_t *smart_source, lbm_context_t *ctx, + char *topic) +{ + lbm_topic_t *lbm_topic = NULL; + lbm_src_topic_attr_t *src_tattr = NULL; + int prop_count; + size_t opt_len; + int err; + + smart_source->ctx = ctx; + +/* =semlit,block,send_attr=*/ + err = lbm_src_topic_attr_create(&src_tattr); + LBM_ERR(err); +/* =semlit,endblock,send_attr=*/ + +/* =semlit,block,send_conf_prop=*/ + /* Make sure user's config allows at least 1 msg property. */ + opt_len = sizeof(prop_count); + err = lbm_src_topic_attr_getopt(src_tattr, + "smart_src_message_property_int_count", &prop_count, &opt_len); + LBM_ERR(err); + if (prop_count == 0) { + /* No props configured, add one. */ + prop_count = 1; + opt_len = sizeof(prop_count); + err = lbm_src_topic_attr_setopt(src_tattr, + "smart_src_message_property_int_count", &prop_count, opt_len); + LBM_ERR(err); + } +/* =semlit,endblock,send_conf_prop=*/ + +/* =semlit,block,send_size=*/ + /* Find out the user's config for max message length. */ + opt_len = sizeof(smart_source->max_msg_len); + err = lbm_src_topic_attr_getopt(src_tattr, + "smart_src_max_message_length", &(smart_source->max_msg_len), &opt_len); + LBM_ERR(err); +/* =semlit,endblock,send_size=*/ + + err = lbm_src_topic_alloc(&lbm_topic, ctx, topic, src_tattr); + LBM_ERR(err); + + err = lbm_ssrc_create(&(smart_source->ssrc), ctx, lbm_topic, NULL, NULL, + NULL); + LBM_ERR(err); + + err = lbm_src_topic_attr_delete(src_tattr); + LBM_ERR(err); + +/* =semlit,block,send_buffs=*/ + err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_plain, 0); + LBM_ERR(err); + err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_props, 0); + LBM_ERR(err); +/* =semlit,endblock,send_buffs=*/ + +/* =semlit,block,send_props=*/ + /* Set up message property. */ + smart_source->info_prop.flags = LBM_SSRC_SEND_EX_FLAG_PROPERTIES; + smart_source->info_prop.mprop_int_cnt = 1; + smart_source->info_prop.mprop_int_vals = smart_source->int_value_array; + smart_source->info_prop.mprop_int_keys = &smart_source->key_ptr_array[0]; + smart_source->key_ptr_array[0] = smart_source->remain_key; + strncpy(smart_source->remain_key, "Remain", sizeof(smart_source->remain_key)); +/* =semlit,endblock,send_props=*/ +} /* smart_source_init */ + + +/* =semlit,block,send_funct=*/ +/* Send a message, fragmenting it if necessary. + */ +void smart_source_send(smart_source_t *smart_source, char *buf, size_t len, + int flags) +{ +/* =semlit,endblock,send_funct=*/ + int err; + +/* =semlit,block,send_check=*/ + if (len <= smart_source->max_msg_len) { + /* Message fits in one buffer, send it. */ + memcpy(smart_source->msgbuf_plain, buf, len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_plain, + len, 0, NULL); + LBM_ERR(err); + } +/* =semlit,endblock,send_check=*/ + + else { /* Message does not fit in one buffer */ + int offset; + int remaining; + int this_len; + + /* Fragment message. */ + remaining = len; + offset = 0; + +/* =semlit,block,send_first=*/ + this_len = smart_source->max_msg_len; + remaining -= this_len; + /* Indicate first fragment with negative remainer. */ + smart_source->int_value_array[0] = - remaining; + memcpy(smart_source->msgbuf_props, &buf[offset], this_len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, + this_len, 0, &(smart_source->info_prop)); + LBM_ERR(err); + offset += this_len; +/* =semlit,endblock,send_first=*/ + + /* From now on, need to update the properties. */ + smart_source->info_prop.flags |= LBM_SSRC_SEND_EX_FLAG_UPDATE_PROPERTY_VALUES; + +/* =semlit,block,send_rest=*/ + /* Send rest of fragments. */ + while (remaining > 0) { + if (remaining > smart_source->max_msg_len) { + this_len = smart_source->max_msg_len; + } + else { + this_len = remaining; + } + remaining -= this_len; + smart_source->int_value_array[0] = remaining; + memcpy(smart_source->msgbuf_props, &buf[offset], this_len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, + this_len, 0, &(smart_source->info_prop)); + + offset += this_len; + } /* while */ +/* =semlit,endblock,send_rest=*/ + } +} /* smart_source_send */ + + +int main(int argc, char **argv) { + lbm_context_t *rctx = NULL; + lbm_context_t *sctx = NULL; + lbm_rcv_topic_attr_t *rcv_attr = NULL; + lbm_rcv_src_notification_func_t src_notif_func; /* config option */ + lbm_topic_t *lbm_topic = NULL; + lbm_rcv_t *rcv; + smart_source_t smart_source; + char *send_buff; + int err; + + err = lbm_config("test.cfg"); + LBM_ERR(err); + + /* Create a pair of contexts, one for publisher, the other for subscriber. + */ + + err = lbm_context_create(&rctx, NULL, NULL, NULL); + LBM_ERR(err); + + err = lbm_context_create(&sctx, NULL, NULL, NULL); + LBM_ERR(err); + + + /* Create receiver. + */ + + err = lbm_rcv_topic_attr_create(&rcv_attr); + LBM_ERR(err); + + src_notif_func.create_func = per_src_clientd_create; + src_notif_func.delete_func = per_src_clientd_delete; + src_notif_func.clientd = NULL; /* Or your own state structure. */ + err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", + &src_notif_func, sizeof(src_notif_func)); + LBM_ERR(err); + + err = lbm_rcv_topic_lookup(&lbm_topic, rctx, "topic_1", rcv_attr); + LBM_ERR(err); + + err = lbm_rcv_create(&rcv, rctx, lbm_topic, msg_rcv_cb, NULL, NULL); + LBM_ERR(err); + + + /* Create source. + */ + smart_source_init(&smart_source, sctx, "topic_1"); + + send_buff = (char *)malloc(70000); /* Bigger than 64k, for fun. */ + + SLEEP(1); /* For topic res. */ + + + /* Send messages. + */ + + send_buff[0] = 1; send_buff[999] = 1; + smart_source_send(&smart_source, send_buff, 1000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 2; send_buff[4999] = 2; + smart_source_send(&smart_source, send_buff, 5000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 3; send_buff[19999] = 3; + smart_source_send(&smart_source, send_buff, 20000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 4; send_buff[99] = 4; + smart_source_send(&smart_source, send_buff, 100, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 5; send_buff[69999] = 5; + smart_source_send(&smart_source, send_buff, 70000, LBM_MSG_FLUSH); + SLEEP(1); + + + /* Shut down. + */ + + free(send_buff); + + (void)lbm_ssrc_delete(smart_source.ssrc); + (void)lbm_rcv_delete(rcv); + + (void)lbm_context_delete(rctx); + (void)lbm_context_delete(sctx); + + return 0; +} /* main */ diff --git a/ss_frag/c/ss_frag_c.slsrc.html b/ss_frag/c/ss_frag_c.slsrc.html new file mode 100644 index 0000000..3862191 --- /dev/null +++ b/ss_frag/c/ss_frag_c.slsrc.html @@ -0,0 +1,1022 @@ + ss_frag.c + + + + + + + + +ss_frag.c
+ +diff --git a/ss_frag/c/test.cfg b/ss_frag/c/test.cfg new file mode 100644 index 0000000..61b105f --- /dev/null +++ b/ss_frag/c/test.cfg @@ -0,0 +1,11 @@ +# test.cfg + +source transport lbtrm +source smart_src_max_message_length 1400 +source smart_src_message_property_int_count 2 +source smart_src_user_buffer_count 2 + +# The following should be uncommented and changed according to your network. +#context resolver_multicast_address 239.101.3.1 +#context transport_lbtrm_multicast_address_low 239.101.3.10 +#context transport_lbtrm_multicast_address_high 239.101.3.14 diff --git a/ss_frag/c/test_cfg.txt b/ss_frag/c/test_cfg.txt new file mode 100644 index 0000000..61b105f --- /dev/null +++ b/ss_frag/c/test_cfg.txt @@ -0,0 +1,11 @@ +# test.cfg + +source transport lbtrm +source smart_src_max_message_length 1400 +source smart_src_message_property_int_count 2 +source smart_src_user_buffer_count 2 + +# The following should be uncommented and changed according to your network. +#context resolver_multicast_address 239.101.3.1 +#context transport_lbtrm_multicast_address_low 239.101.3.10 +#context transport_lbtrm_multicast_address_high 239.101.3.14 diff --git a/ss_frag/c/test_cfg.txt.html b/ss_frag/c/test_cfg.txt.html new file mode 100644 index 0000000..9b8aaff --- /dev/null +++ b/ss_frag/c/test_cfg.txt.html @@ -0,0 +1,126 @@ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 00001 +00002 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 +00017 +00018 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 +00149 +00150 +00151 +00152 +00153 +00154 +00155 +00156 +00157 +00158 +00159 +00160 +00161 +00162 +00163 +00164 +00165 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 +00181 +00182 +00183 +00184 +00185 +00186 +00187 +00188 +00189 +00190 +00191 +00192 +00193 +00194 +00195 +00196 +00197 +00198 +00199 +00200 +00201 +00202 +00203 +00204 +00205 +00206 +00207 +00208 +00209 +00210 +00211 +00212 +00213 +00214 +00215 +00216 +00217 +00218 +00219 +00220 +00221 +00222 +00223 +00224 +00225 +00226 +00227 +00228 +00229 +00230 +00231 +00232 +00233 +00234 +00235 +00236 +00237 +00238 +00239 +00240 +00241 +00242 +00243 +00244 +00245 +00246 +00247 +00248 +00249 +00250 +00251 +00252 +00253 +00254 +00255 +00256 +00257 +00258 +00259 +00260 +00261 +00262 +00263 +00264 +00265 +00266 +00267 +00268 +00269 +00270 +00271 +00272 +00273 +00274 +00275 +00276 +00277 +00278 +00279 +00280 +00281 +00282 +00283 +00284 +00285 +00286 +00287 +00288 +00289 +00290 +00291 +00292 +00293 +00294 +00295 +00296 +00297 +00298 +00299 +00300 +00301 +00302 +00303 +00304 +00305 +00306 +00307 +00308 +00309 +00310 +00311 +00312 +00313 +00314 +00315 +00316 +00317 +00318 +00319 +00320 +00321 +00322 +00323 +00324 +00325 +00326 +00327 +00328 +00329 +00330 +00331 +00332 +00333 +00334 +00335 +00336 +00337 +00338 +00339 +00340 +00341 +00342 +00343 +00344 +00345 +00346 +00347 +00348 +00349 +00350 +00351 +00352 +00353 +00354 +00355 +00356 +00357 +00358 +00359 +00360 +00361 +00362 +00363 +00364 +00365 +00366 +00367 +00368 +00369 +00370 +00371 +00372 +00373 +00374 +00375 +00376 +00377 +00378 +00379 +00380 +00381 +00382 +00383 +00384 +00385 +00386 +00387 +00388 +00389 +00390 +00391 +00392 +00393 +00394 +00395 +00396 +00397 +00398 +00399 +00400 +00401 +00402 +00403 +00404 +00405 +00406 +00407 +00408 +00409 +00410 +00411 +00412 +00413 +00414 +00415 +00416 +00417 +00418 +00419 +00420 +00421 +00422 +00423 +00424 +00425 +00426 +00427 +00428 +00429 +00430 +00431 +00432 +00433 +00434 +00435 +00436 +00437 +00438 +00439 +00440 +00441 +00442 +00443 +00444 +00445 +00446 +00447 +00448 +00449 +00450 +00451 +00452 +00453 +00454 +00455 +00456 +00457 +00458 +00459 + /* ss_frag.c - see http://ultramessaging.github.io/UMExamples/ss_frag/c/index.html + * + * Copyright (c) 2005-2018 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ + + #include <stdio.h> + #include <string.h> + + #if defined(_MSC_VER) + /* Windows-only includes */ + #include <winsock2.h> + #define SLEEP(s) Sleep((s)*1000) + #else + /* Unix-only includes */ + #include <stdlib.h> + #include <unistd.h> + #define SLEEP(s) sleep(s) + #endif + + #include <lbm/lbm.h> + + + /* Application structure associated with a smart source. + */ + typedef struct { + lbm_context_t *ctx; + lbm_ssrc_t *ssrc; + char *msgbuf_plain; + char *msgbuf_props; + int max_msg_len; + lbm_ssrc_send_ex_info_t info_prop; + lbm_uint32_t int_value_array[2]; + char *key_ptr_array[2]; + char remain_key[8]; + } smart_source_t; + + + /* Receiver state used to reassemble fragmented messages. Used as per-source + * clientd. + */ + typedef struct { + int collecting; /* 1=true, 0=false. */ + char *reassem_buf; + size_t reassem_buf_size; + size_t message_len; /* Size of message being reassembled. */ + size_t offset; /* Current offset within reassem_buf[]. */ + long num_bad_frags; /* Statistic: bad fragemnts. */ + } rcv_state_t; + + + /* + * Simple lbm error handling. + */ + + /* Macro to approximate the basename() function. */ + #define BASENAME(_p) ((strrchr(_p, '/') == NULL) ? (_p) : (strrchr(_p, '/')+1)) + + /* Pass in an LBM return status. If not success, print error and abort. */ + #define LBM_ERR(_e) do {\ + if ((_e) != LBM_OK) {\ + printf("LBM_ERR: at %s:%d (%s)\n",\ + BASENAME(__FILE__), __LINE__, lbm_errmsg());\ + fflush(stdout);\ + abort();\ + }\ + } while (0) + + /* Print error and abort. */ + #define ERR(_s) do {\ + printf("ERR: at %s:%d (%s)\n",\ + BASENAME(__FILE__), __LINE__, _s);\ + fflush(stdout);\ + abort();\ + } while (0) + + + /* Called by receiver callback when a received messager has the "Remain" + * message property, indicating a fragmented message. + */ + void handle_msg_frag(lbm_msg_t *msg, rcv_state_t *rcv_state, + lbm_int32_t remaining) + { + size_t tot_len; + + if (rcv_state->collecting) { + /* Make sure the fragment is OK. */ + if (remaining >= 0 && + (rcv_state->message_len == (rcv_state->offset + msg->len + remaining))) + { + /* Collect the fragment. */ + memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, + msg->len); + rcv_state->offset += msg->len; + + if (remaining == 0) { /* No more, deliver the data. */ + printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", + rcv_state->reassem_buf[0], + rcv_state->message_len - 1, + rcv_state->reassem_buf[rcv_state->message_len - 1]); + + /* No longer collecting. */ + rcv_state->collecting = 0; + } + } /* if fragment OK */ + else { /* fragment is not ok. */ + /* Bad fragment (should never happen). */ + printf("Collect error: bad fragment, remaining=%d, offset=%ld, len=%lu, message_len=%ld\n", remaining, rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->num_bad_frags ++; + + /* Error, stop collecting. */ + rcv_state->collecting = 0; + } + } + + else { /* not collecting */ + /* Not collecting a fragmented message, is this message first frag? */ + if (remaining < 0) { + /* First fragment. */ + rcv_state->collecting = 1; + rcv_state->offset = 0; + rcv_state->message_len = msg->len + (- remaining); + /* Expand buffer if necessary. */ + if (rcv_state->message_len > rcv_state->reassem_buf_size) { + rcv_state->reassem_buf_size = rcv_state->message_len; + rcv_state->reassem_buf = (char *)realloc(rcv_state->reassem_buf, + rcv_state->reassem_buf_size); + } + + /* Collect data. */ + memcpy(&rcv_state->reassem_buf[rcv_state->offset], msg->data, msg->len); + rcv_state->offset += msg->len; + } /* remaining < 0 */ + else { /* Found middle frag without a first frag; discard. */ + /* Probably joined stream in middle of message. */ + printf("info: found middle frag but not collecting, remaining=%d, offset=%ld, len=%lu, message_len=%ld\n", remaining, rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->num_bad_frags ++; + } + } /* not collecting */ + } /* handle_msg_frag */ + + + /* UM receiver callback. + */ + int msg_rcv_cb(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) + { + rcv_state_t *rcv_state = (rcv_state_t *)msg->source_clientd; + int err; + + switch (msg->type) { + case LBM_MSG_DATA: + if (msg->properties == NULL) { + /* Fast path (not part of a fragmented messqge). */ + if (rcv_state->collecting) { + /* Error, non-frag, but state is collecting (should never happen). */ + printf("Collect error non-frag, offset=%ld, len=%lu, message_len=%ld\n", rcv_state->offset, msg->len, rcv_state->message_len); + rcv_state->collecting = 0; + rcv_state->num_bad_frags ++; + } + + /* Deliver data message. */ + printf("PROCESS message, buf[0]=%d, buf[%ld]=%d\n", + msg->data[0], + msg->len - 1, + msg->data[msg->len - 1]); + } + else { /* msg properties */ + lbm_int32_t remaining; + size_t prop_size = sizeof(remaining); + int prop_type = LBM_MSG_PROPERTY_INT; + + /* Found property, is it for fragmentation? */ + err = lbm_msg_properties_get(msg->properties, "Remain", + &remaining, &prop_type, &prop_size); + if (err == LBM_OK) { + handle_msg_frag(msg, rcv_state, remaining); + } + else { + printf("handle messages with other properties.\n"); + } + } /* msg properties not null */ + break; + + case LBM_MSG_UNRECOVERABLE_LOSS: + case LBM_MSG_UNRECOVERABLE_LOSS_BURST: + if (rcv_state->collecting) { + /* Stop collecting after error. */ + rcv_state->collecting = 0; + rcv_state->num_bad_frags ++; + } + + default: + printf("Non data receiver event, type=%d\n", msg->type); + } /* switch msg type */ + + return 0; + } /* msg_rcv_cb */ + + + /* Callback when a receiver delivery controller is created for a new source. */ + void *per_src_clientd_create(const char *source_name, void *clientd) + { + rcv_state_t *rcv_state; + + rcv_state = (rcv_state_t *)malloc(sizeof(rcv_state_t)); + + rcv_state->reassem_buf_size = 8192; + rcv_state->reassem_buf = (char *)malloc(rcv_state->reassem_buf_size); + rcv_state->collecting = 0; + rcv_state->num_bad_frags = 0; + + return rcv_state; + } /* per_src_clientd_create */ + + + /* Callback when a receiver delivery controller for an ex-source is deleted. */ + int per_src_clientd_delete(const char *source_name, void *clientd, + void *src_clientd) + { + rcv_state_t *rcv_state = (rcv_state_t *)src_clientd; + + if (rcv_state->collecting) { + /* Error, state is collecting. */ + printf("Collect error, incomplete fragmented message, offset=%ld, message_len=%ld\n", rcv_state->offset, rcv_state->message_len); + } + if (rcv_state->num_bad_frags > 0) { + printf("Number of bad fragments=%ld\n", rcv_state->num_bad_frags); + } + + free(rcv_state->reassem_buf); + free(rcv_state); + + return 0; + } /* per_src_clientd_delete */ + + + /* Create a SmartSource, and init associated state. + */ + void smart_source_init(smart_source_t *smart_source, lbm_context_t *ctx, + char *topic) + { + lbm_topic_t *lbm_topic = NULL; + lbm_src_topic_attr_t *src_tattr = NULL; + int prop_count; + size_t opt_len; + int err; + + smart_source->ctx = ctx; + + err = lbm_src_topic_attr_create(&src_tattr); + LBM_ERR(err); + + /* Make sure user's config allows at least 1 msg property. */ + opt_len = sizeof(prop_count); + err = lbm_src_topic_attr_getopt(src_tattr, + "smart_src_message_property_int_count", &prop_count, &opt_len); + LBM_ERR(err); + if (prop_count == 0) { + /* No props configured, add one. */ + prop_count = 1; + opt_len = sizeof(prop_count); + err = lbm_src_topic_attr_setopt(src_tattr, + "smart_src_message_property_int_count", &prop_count, opt_len); + LBM_ERR(err); + } + + /* Find out the user's config for max message length. */ + opt_len = sizeof(smart_source->max_msg_len); + err = lbm_src_topic_attr_getopt(src_tattr, + "smart_src_max_message_length", &(smart_source->max_msg_len), &opt_len); + LBM_ERR(err); + + err = lbm_src_topic_alloc(&lbm_topic, ctx, topic, src_tattr); + LBM_ERR(err); + + err = lbm_ssrc_create(&(smart_source->ssrc), ctx, lbm_topic, NULL, NULL, + NULL); + LBM_ERR(err); + + err = lbm_src_topic_attr_delete(src_tattr); + LBM_ERR(err); + + err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_plain, 0); + LBM_ERR(err); + err = lbm_ssrc_buff_get(smart_source->ssrc, &smart_source->msgbuf_props, 0); + LBM_ERR(err); + + /* Set up message property. */ + smart_source->info_prop.flags = LBM_SSRC_SEND_EX_FLAG_PROPERTIES; + smart_source->info_prop.mprop_int_cnt = 1; + smart_source->info_prop.mprop_int_vals = smart_source->int_value_array; + smart_source->info_prop.mprop_int_keys = &smart_source->key_ptr_array[0]; + smart_source->key_ptr_array[0] = smart_source->remain_key; + strncpy(smart_source->remain_key, "Remain", sizeof(smart_source->remain_key)); + } /* smart_source_init */ + + + /* Send a message, fragmenting it if necessary. + */ + void smart_source_send(smart_source_t *smart_source, char *buf, size_t len, + int flags) + { + int err; + + if (len <= smart_source->max_msg_len) { + /* Message fits in one buffer, send it. */ + memcpy(smart_source->msgbuf_plain, buf, len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_plain, + len, 0, NULL); + LBM_ERR(err); + } + + else { /* Message does not fit in one buffer */ + int offset; + int remaining; + int this_len; + + /* Fragment message. */ + remaining = len; + offset = 0; + + this_len = smart_source->max_msg_len; + remaining -= this_len; + /* Indicate first fragment with negative remainer. */ + smart_source->int_value_array[0] = - remaining; + memcpy(smart_source->msgbuf_props, &buf[offset], this_len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, + this_len, 0, &(smart_source->info_prop)); + LBM_ERR(err); + offset += this_len; + + /* From now on, need to update the properties. */ + smart_source->info_prop.flags |= LBM_SSRC_SEND_EX_FLAG_UPDATE_PROPERTY_VALUES; + + /* Send rest of fragments. */ + while (remaining > 0) { + if (remaining > smart_source->max_msg_len) { + this_len = smart_source->max_msg_len; + } + else { + this_len = remaining; + } + remaining -= this_len; + smart_source->int_value_array[0] = remaining; + memcpy(smart_source->msgbuf_props, &buf[offset], this_len); + err = lbm_ssrc_send_ex(smart_source->ssrc, smart_source->msgbuf_props, + this_len, 0, &(smart_source->info_prop)); + + offset += this_len; + } /* while */ + } + } /* smart_source_send */ + + + int main(int argc, char **argv) { + lbm_context_t *rctx = NULL; + lbm_context_t *sctx = NULL; + lbm_rcv_topic_attr_t *rcv_attr = NULL; + lbm_rcv_src_notification_func_t src_notif_func; /* config option */ + lbm_topic_t *lbm_topic = NULL; + lbm_rcv_t *rcv; + smart_source_t smart_source; + char *send_buff; + int err; + + err = lbm_config("test.cfg"); + LBM_ERR(err); + + /* Create a pair of contexts, one for publisher, the other for subscriber. + */ + + err = lbm_context_create(&rctx, NULL, NULL, NULL); + LBM_ERR(err); + + err = lbm_context_create(&sctx, NULL, NULL, NULL); + LBM_ERR(err); + + + /* Create receiver. + */ + + err = lbm_rcv_topic_attr_create(&rcv_attr); + LBM_ERR(err); + + src_notif_func.create_func = per_src_clientd_create; + src_notif_func.delete_func = per_src_clientd_delete; + src_notif_func.clientd = NULL; /* Or your own state structure. */ + err = lbm_rcv_topic_attr_setopt(rcv_attr, "source_notification_function", + &src_notif_func, sizeof(src_notif_func)); + LBM_ERR(err); + + err = lbm_rcv_topic_lookup(&lbm_topic, rctx, "topic_1", rcv_attr); + LBM_ERR(err); + + err = lbm_rcv_create(&rcv, rctx, lbm_topic, msg_rcv_cb, NULL, NULL); + LBM_ERR(err); + + + /* Create source. + */ + smart_source_init(&smart_source, sctx, "topic_1"); + + send_buff = (char *)malloc(70000); /* Bigger than 64k, for fun. */ + + SLEEP(1); /* For topic res. */ + + + /* Send messages. + */ + + send_buff[0] = 1; send_buff[999] = 1; + smart_source_send(&smart_source, send_buff, 1000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 2; send_buff[4999] = 2; + smart_source_send(&smart_source, send_buff, 5000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 3; send_buff[19999] = 3; + smart_source_send(&smart_source, send_buff, 20000, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 4; send_buff[99] = 4; + smart_source_send(&smart_source, send_buff, 100, LBM_MSG_FLUSH); + SLEEP(1); + + send_buff[0] = 5; send_buff[69999] = 5; + smart_source_send(&smart_source, send_buff, 70000, LBM_MSG_FLUSH); + SLEEP(1); + + + /* Shut down. + */ + + free(send_buff); + + (void)lbm_ssrc_delete(smart_source.ssrc); + (void)lbm_rcv_delete(rcv); + + (void)lbm_context_delete(rctx); + (void)lbm_context_delete(sctx); + + return 0; + } /* main */ + test.cfg + + + + + + + + +test.cfg
+ +diff --git a/ss_frag/intro.sldoc b/ss_frag/intro.sldoc new file mode 100644 index 0000000..e8cae58 --- /dev/null +++ b/ss_frag/intro.sldoc @@ -0,0 +1,56 @@ +Example index ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 00001 +00002 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 + # test.cfg + + source transport lbtrm + source smart_src_max_message_length 1400 + source smart_src_message_property_int_count 2 + source smart_src_user_buffer_count 2 + + # The following should be uncommented and changed according to your network. + #context resolver_multicast_address 239.101.3.1 + #context transport_lbtrm_multicast_address_low 239.101.3.10 + #context transport_lbtrm_multicast_address_high 239.101.3.14 + Smart Source Message Fragmentation
+Ultra Messaging has a feature called + Smart Sources + which provides lower average latency and much lower latency + variation (jitter) than traditional UM sources. + Smart Sources are able to deliver these benefits by trading off reduced + flexibility for simplicity, especially simplicity in memory usage.
+One area of reduced flexibility is related to message sizes. + To avoid dynamic memory allocation/deallocation, Smart Sources require + the user to configure the maximum expected message size. + Also, Smart Sources do not support fragmentation and reassembly of + messages larger than the maximum datagram size. + An application message must fit in a single datagram. + Finally, users of kernel bypass TCP/IP stacks (like Solarflare's Onload) + pay a heavy penalty if IP fragmentation is performed by the kernel. + These users typically want to keep each datagram at or below the + NIC's MTU size (typically 1500 bytes).
+However, many applications have a fairly small average message size, + but occasionally need to send messages that are much larger. + If that worst-case large message size is larger than an MTU, + it cannot be efficiently sent using Onload or other kernel bypass stacks.
+Also, even if IP fragmentation is not a problem, + a Smart Sources pre-allocates its retransmission buffers based on the + worst-case message size. + For applications that normally send small messages but occasionally + need to send very large ones, + this can lead to a significant memory footprint.
+One solution to these problems is for an application to configure Smart + Source for small messages, and perform message fragmentation and + reassembly at the application level. + This example program does just that.
+High-Level Design
+An integer message property with key name "Remain" is used to manage + message fragmentation and reassembly. + Small messages may be sent without a property. + Messages which exceed a configured threshold will be sent in "chunks", + with a message property providing the information needed by the + receiver to reassemble the chunks.
+When the application wants to send a message larger than + [smart_src_max_message_length (source)](https://ultramessaging.github.io/currdoc/doc/Config/grpsmartsource.html#smartsrcmaxmessagelengthsource), + the first fragment is sent with the "Remain" property is a negative + number representing the number of bytes that still need to be sent + (not counting the content of that first message). + Each subsequent message fragment sent has the "Remain" property as + a positive number of the number of bytes remaining + after that message.
+For example, if smart_src_max_message_length is set to 1400 and a + 5000 byte message is sent, 4 UM messages will be sent. + Here are the message lengths and values for the "Remain" property:
++
- length=1400, Remain=-3600
+- length=1400, Remain=2200
+- length=1400, Remain=800
+- length=800, Remain=0
+When the receiver sees Remain=0, it can deliver the reassembled message.
diff --git a/style/doxygen_manual.css b/style/doxygen_manual.css new file mode 100644 index 0000000..c9d6a06 --- /dev/null +++ b/style/doxygen_manual.css @@ -0,0 +1,1114 @@ +/* The standard CSS for doxygen */ + +body, table, div, p, dl { + font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif; + font-size: 13px; + line-height: 1.3; +} + +/* @group Heading Levels */ + +h1 { + font-size: 150%; +} + +.mytitle { + font-size: 350%; + font-weight: bold; + margin: 10px 2px; +} + +.title { + font-size: 150%; + font-weight: bold; + margin: 10px 2px; +} + +h2 { + font-size: 120%; +} + +h3 { + font-size: 100%; +} + +h1, h2, h3, h4, h5, h6 { + -webkit-transition: text-shadow 0.5s linear; + -moz-transition: text-shadow 0.5s linear; + -ms-transition: text-shadow 0.5s linear; + -o-transition: text-shadow 0.5s linear; + transition: text-shadow 0.5s linear; + margin-right: 15px; +} + +h1.glow, h2.glow, h3.glow, h4.glow, h5.glow, h6.glow { + text-shadow: 0 0 15px cyan; +} + +dt { + font-weight: bold; +} + +div.multicol { + -moz-column-gap: 1em; + -webkit-column-gap: 1em; + -moz-column-count: 3; + -webkit-column-count: 3; +} + +p.startli, p.startdd, p.starttd { + margin-top: 2px; +} + +p.endli { + margin-bottom: 0px; +} + +p.enddd { + margin-bottom: 4px; +} + +p.endtd { + margin-bottom: 2px; +} + +/* @end */ + +caption { + font-weight: bold; +} + +span.legend { + font-size: 70%; + text-align: center; +} + +h3.version { + font-size: 90%; + text-align: center; +} + +div.qindex, div.navtab{ + background-color: #F1F1F1; + border: 1px solid #BDBDBD; + text-align: center; +} + +div.qindex, div.navpath { + width: 100%; + line-height: 140%; +} + +div.navtab { + margin-right: 15px; +} + +/* @group Link Styling */ + +a { + color: #6464FF; + font-weight: normal; + text-decoration: none; +} + +.contents a:visited { + color: white; +} + +a:hover { + text-decoration: underline; +} + +a.qindex { + font-weight: bold; +} + +a.qindexHL { + font-weight: bold; + background-color: #B8B8B8; + color: #ffffff; + border: 1px double #A8A8A8; +} + +.contents a.qindexHL:visited { + color: #ffffff; +} + +a.el { + font-weight: bold; +} + +a.elRef { +} + +a.code, a.code:visited { + color: #4665A2; +} + +a.codeRef, a.codeRef:visited { + color: #4665A2; +} + +/* @end */ + +dl.el { + margin-left: -1cm; +} + +pre.fragment { + border: 1px solid #C4CFE5; + background-color: #FBFCFD; + padding: 4px 6px; + margin: 4px 8px 4px 2px; + overflow: auto; + word-wrap: break-word; + font-size: 9pt; + line-height: 125%; + font-family: monospace, fixed; + font-size: 105%; +} + +div.fragment { + padding: 4px; + margin: 4px; + background-color: #FCFCFC; + border: 1px solid #D5D5D5; +} + +div.line { + font-family: monospace, fixed; + font-size: 13px; + line-height: 1.0; + text-wrap: unrestricted; + white-space: -moz-pre-wrap; /* Moz */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: pre-wrap; /* CSS3 */ + word-wrap: break-word; /* IE 5.5+ */ + text-indent: -53px; + padding-left: 53px; + padding-bottom: 0px; + margin: 0px; +} + +span.lineno { + padding-right: 4px; + text-align: right; + border-right: 2px solid #0F0; + background-color: #E8E8E8; + white-space: pre; +} +span.lineno a { + background-color: #D8D8D8; +} + +span.lineno a:hover { + background-color: #C8C8C8; +} + +div.ah { + background-color: black; + font-weight: bold; + color: #ffffff; + margin-bottom: 3px; + margin-top: 3px; + padding: 0.2em; + border: solid thin #333; + border-radius: 0.5em; + -webkit-border-radius: .5em; + -moz-border-radius: .5em; + box-shadow: 2px 2px 3px #999; + -webkit-box-shadow: 2px 2px 3px #999; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + background-image: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#000),color-stop(0.3, #444)); + background-image: -moz-linear-gradient(center top, #eee 0%, #444 40%, #000); +} + +div.groupHeader { + margin-left: 16px; + margin-top: 12px; + font-weight: bold; +} + +div.groupText { + margin-left: 16px; + font-style: italic; +} + +body { + background-color: #CCCCCC; + color: black; + margin: 0; +} + +div.contents { + margin-bottom: 10px; + padding: 12px; + margin-left: auto; + margin-right: auto; + width: 800px; + background-color: white; + -moz-border-radius-bottomleft: 8px; + -moz-border-radius-bottomright: 8px; + /* firefox specific markup */ + -moz-box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 5px; + /* webkit specific markup */ + -webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.15); +} + +td.indexkey { + background-color: #F1F1F1; + font-weight: bold; + border: 1px solid #D5D5D5; + margin: 2px 0px 2px 0; + padding: 2px 10px; + white-space: nowrap; + vertical-align: top; +} + +td.indexvalue { + background-color: #F1F1F1; + border: 1px solid #D5D5D5; + padding: 2px 10px; + margin: 2px 0px; +} + +tr.memlist { + background-color: #F2F2F2; +} + +p.formulaDsp { + text-align: center; +} + +img.formulaDsp { + +} + +img.formulaInl { + vertical-align: middle; +} + +div.center { + text-align: center; + margin-top: 0px; + margin-bottom: 0px; + padding: 0px; +} + +div.center img { + border: 0px; +} + +address.footer { + text-align: right; + padding-right: 12px; + background-color: #8080A0; + color: white; +} + +img.footer { + border: 0px; + vertical-align: middle; +} + +/* @group Code Colorization */ + +span.keyword { + color: #008000 +} + +span.keywordtype { + color: #604020 +} + +span.keywordflow { + color: #e08000 +} + +span.comment { + color: #800000 +} + +span.preprocessor { + color: #806020 +} + +span.stringliteral { + color: #002080 +} + +span.charliteral { + color: #008080 +} + +span.vhdldigit { + color: #ff00ff +} + +span.vhdlchar { + color: #000000 +} + +span.vhdlkeyword { + color: #700070 +} + +span.vhdllogic { + color: #ff0000 +} + +blockquote { + background-color: #F9F9F9; + border-left: 2px solid #B8B8B8; + margin: 0 24px 0 4px; + padding: 0 12px 0 16px; +} + +/* @end */ + +/* +.search { + color: #003399; + font-weight: bold; +} + +form.search { + margin-bottom: 0px; + margin-top: 0px; +} + +input.search { + font-size: 75%; + color: #000080; + font-weight: normal; + background-color: #e8eef2; +} +*/ + +td.tiny { + font-size: 75%; +} + +.dirtab { + padding: 4px; + border-collapse: collapse; + border: 1px solid #BDBDBD; +} + +th.dirtab { + background: #F1F1F1; + font-weight: bold; +} + +hr { + height: 0px; + border: none; + border-top: 1px solid #7A7A7A; +} + +hr.footer { + display: none; +} + +/* @group Member Descriptions */ + +table.memberdecls { + border-spacing: 0px; + padding: 0px; +} + +.mdescLeft, .mdescRight, +.memItemLeft, .memItemRight, +.memTemplItemLeft, .memTemplItemRight, .memTemplParams { + background-color: #FAFAFA; + border: none; + margin: 4px; + padding: 1px 0 0 8px; +} + +.mdescLeft, .mdescRight { + padding: 0px 8px 4px 8px; + color: #555; +} + +.memItemLeft, .memItemRight, .memTemplParams { + border-top: 1px solid #D5D5D5; +} + +.memItemLeft, .memTemplItemLeft { + white-space: nowrap; +} + +.memItemRight { + width: 100%; +} + +.memTemplParams { + color: #747474; + white-space: nowrap; +} + +/* @end */ + +/* @group Member Details */ + +/* Styles for detailed member documentation */ + +.memtemplate { + font-size: 80%; + color: #747474; + font-weight: normal; + margin-left: 9px; +} + +.memnav { + background-color: #F1F1F1; + border: 1px solid #BDBDBD; + text-align: center; + margin: 2px; + margin-right: 15px; + padding: 2px; +} + +.mempage { + width: 100%; +} + +.memitem { + padding: 0; + margin-bottom: 10px; + margin-right: 5px; + -webkit-transition: box-shadow 0.5s linear; + -moz-transition: box-shadow 0.5s linear; + -ms-transition: box-shadow 0.5s linear; + -o-transition: box-shadow 0.5s linear; + transition: box-shadow 0.5s linear; +} + +.memitem.glow { + box-shadow: 0 0 15px cyan; +} + +.memname { + white-space: nowrap; + font-weight: bold; + margin-left: 6px; +} + +.memproto, dl.reflist dt { + border-top: 1px solid #C0C0C0; + border-left: 1px solid #C0C0C0; + border-right: 1px solid #C0C0C0; + padding: 6px 0px 6px 0px; + color: #3D3D3D; + font-weight: bold; + text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.9); + /* opera specific markup */ + box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + border-top-right-radius: 8px; + border-top-left-radius: 8px; + /* firefox specific markup */ + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + -moz-border-radius-topright: 8px; + -moz-border-radius-topleft: 8px; + /* webkit specific markup */ + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + -webkit-border-top-right-radius: 8px; + -webkit-border-top-left-radius: 8px; + background-image:url('nav_f.png'); + background-repeat:repeat-x; + background-color: #EAEAEA; + +} + +.memdoc, dl.reflist dd { + border-bottom: 1px solid #C0C0C0; + border-left: 1px solid #C0C0C0; + border-right: 1px solid #C0C0C0; + padding: 2px 5px; + background-color: #FCFCFC; + border-top-width: 0; + /* opera specific markup */ + border-bottom-left-radius: 8px; + border-bottom-right-radius: 8px; + box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + /* firefox specific markup */ + -moz-border-radius-bottomleft: 8px; + -moz-border-radius-bottomright: 8px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 5px 5px 5px; + background-image: -moz-linear-gradient(center top, #FFFFFF 0%, #FFFFFF 60%, #F9F9F9 95%, #F2F2F2); + /* webkit specific markup */ + -webkit-border-bottom-left-radius: 8px; + -webkit-border-bottom-right-radius: 8px; + -webkit-box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.15); + background-image: -webkit-gradient(linear,center top,center bottom,from(#FFFFFF), color-stop(0.6,#FFFFFF), color-stop(0.60,#FFFFFF), color-stop(0.95,#F9F9F9), to(#F2F2F2)); +} + +dl.reflist dt { + padding: 5px; +} + +dl.reflist dd { + margin: 0px 0px 10px 0px; + padding: 5px; +} + +.paramkey { + text-align: right; +} + +.paramtype { + white-space: nowrap; +} + +.paramname { + color: #602020; + white-space: nowrap; +} +.paramname em { + font-style: normal; +} + +.params, .retval, .exception, .tparams { + border-spacing: 6px 2px; +} + +.params .paramname, .retval .paramname { + font-weight: bold; + vertical-align: top; +} + +.params .paramtype { + font-style: italic; + vertical-align: top; +} + +.params .paramdir { + font-family: "courier new",courier,monospace; + vertical-align: top; +} + + + + +/* @end */ + +/* @group Directory (tree) */ + +/* for the tree view */ + +.ftvtree { + font-family: sans-serif; + margin: 0px; +} + +/* these are for tree view when used as main index */ + +.directory { + font-size: 9pt; + font-weight: bold; + margin: 5px; +} + +.directory h3 { + margin: 0px; + margin-top: 1em; + font-size: 11pt; +} + +/* +The following two styles can be used to replace the root node title +with an image of your choice. Simply uncomment the next two styles, +specify the name of your image and be sure to set 'height' to the +proper pixel height of your image. +*/ + +/* +.directory h3.swap { + height: 61px; + background-repeat: no-repeat; + background-image: url("yourimage.gif"); +} +.directory h3.swap span { + display: none; +} +*/ + +.directory > h3 { + margin-top: 0; +} + +.directory p { + margin: 0px; + white-space: nowrap; +} + +.directory div { + display: none; + margin: 0px; +} + +.directory img { + vertical-align: -30%; +} + +/* these are for tree view when not used as main index */ + +.directory-alt { + font-size: 100%; + font-weight: bold; +} + +.directory-alt h3 { + margin: 0px; + margin-top: 1em; + font-size: 11pt; +} + +.directory-alt > h3 { + margin-top: 0; +} + +.directory-alt p { + margin: 0px; + white-space: nowrap; +} + +.directory-alt div { + display: none; + margin: 0px; +} + +.directory-alt img { + vertical-align: -30%; +} + +/* @end */ + +div.dynheader { + margin-top: 8px; +} + +address { + font-style: normal; + color: #464646; +} + +table.doxtable { + border-collapse:collapse; + margin-top: 4px; + margin-bottom: 4px; +} + +table.doxtable td, table.doxtable th { + border: 1px solid #4A4A4A; + padding: 3px 7px 2px; +} + +table.doxtable th { + background-color: #5B5B5B; + color: #FFFFFF; + font-size: 110%; + padding-bottom: 4px; + padding-top: 5px; + text-align:left; +} + +table.fieldtable { + width: 100%; + margin-bottom: 10px; + border: 1px solid #C0C0C0; + border-spacing: 0px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + border-radius: 4px; + -moz-box-shadow: rgba(0, 0, 0, 0.15) 2px 2px 2px; + -webkit-box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); + box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.15); +} + +.fieldtable td, .fieldtable th { + padding: 3px 7px 2px; +} + +.fieldtable td.fieldtype, .fieldtable td.fieldname { + white-space: nowrap; + border-right: 1px solid #C0C0C0; + border-bottom: 1px solid #C0C0C0; + vertical-align: top; +} + +.fieldtable td.fielddoc { + border-bottom: 1px solid #C0C0C0; + width: 100%; +} + +.fieldtable tr:last-child td { + border-bottom: none; +} + +.fieldtable th { + background-image:url('nav_f.png'); + background-repeat:repeat-x; + background-color: #EAEAEA; + font-size: 90%; + color: #3D3D3D; + padding-bottom: 4px; + padding-top: 5px; + text-align:left; + -moz-border-radius-topleft: 4px; + -moz-border-radius-topright: 4px; + -webkit-border-top-left-radius: 4px; + -webkit-border-top-right-radius: 4px; + border-top-left-radius: 4px; + border-top-right-radius: 4px; + border-bottom: 1px solid #C0C0C0; +} + + +.tabsearch { + top: 0px; + left: 10px; + height: 36px; + background-image: url('tab_b.png'); + z-index: 101; + overflow: hidden; + font-size: 13px; +} + +.navpath ul +{ + font-size: 11px; + background-image:url('tab_b.png'); + background-repeat:repeat-x; + height:30px; + line-height:30px; + color:#ABABAB; + border:solid 1px #D3D3D3; + overflow:hidden; + margin:0px; + padding:0px; +} + +.navpath li +{ + list-style-type:none; + float:left; + padding-left:10px; + padding-right:15px; + background-image:url('bc_s.png'); + background-repeat:no-repeat; + background-position:right; + color:#595959; +} + +.navpath li.navelem a +{ + height:32px; + display:block; + text-decoration: none; + outline: none; +} + +.navpath li.navelem a:hover +{ + color:#929292; +} + +.navpath li.footer +{ + list-style-type:none; + float:right; + padding-left:10px; + padding-right:15px; + background-image:none; + background-repeat:no-repeat; + background-position:right; + color:#595959; + font-size: 8pt; +} + + +div.summary +{ + float: right; + font-size: 8pt; + padding-right: 5px; + width: 50%; + text-align: right; +} + +div.summary a +{ + white-space: nowrap; +} + +div.ingroups +{ + margin-left: 5px; + font-size: 8pt; + padding-left: 5px; + width: 50%; + text-align: left; +} + +div.ingroups a +{ + white-space: nowrap; +} + +div.header +{ + background-image:url('nav_h.png'); + background-repeat:repeat-x; + background-color: #FAFAFA; + border-bottom: 1px solid #D5D5D5; + margin-left: auto; + margin-right: auto; + width: 800px; + padding-left: 12px; + padding-right: 12px; + /* firefox specific markup */ + -moz-box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 5px; + /* webkit specific markup */ + -webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.15); +} + +div.headertitle +{ + padding: 5px 5px 5px 0px; +} + +dl +{ + padding: 0 0 0 10px; +} + +dl.section +{ + padding: 0 0 0 6px; +} + +dl.note +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #D0C000; +} + +dl.warning, dl.attention +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #FF0000; +} + +dl.pre, dl.post, dl.invariant +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #00D000; +} + +dl.deprecated +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #505050; +} + +dl.todo +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #00C0E0; +} + +dl.test +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #3030E0; +} + +dl.bug +{ + margin-left:-7px; + padding-left: 3px; + border-left:4px solid; + border-color: #C08050; +} + +dl.section dd { + margin-bottom: 1em; +} + +#projectlogo +{ + text-align: center; + vertical-align: bottom; + border-collapse: separate; +} + +#projectlogo img +{ + border: 0px none; +} + +#projectname +{ + font: 300% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 2px 0px; +} + +#projectbrief +{ + font: 120% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 0px; +} + +#projectnumber +{ + font: 50% Tahoma, Arial,sans-serif; + margin: 0px; + padding: 0px; +} + +#titlearea +{ + padding: 0px; + margin: 0px; + width: 100%; + border-bottom: 1px solid #848484; + visibility: hidden; + height: 0px; +} + +.image +{ + text-align: center; +} + +.dotgraph +{ + text-align: center; +} + +.mscgraph +{ + text-align: center; +} + +.caption +{ + font-weight: bold; +} + +div.zoom +{ + border: 1px solid #AFAFAF; +} + +dl.citelist { + margin-bottom:50px; +} + +dl.citelist dt { + color:#545454; + float:left; + font-weight:bold; + margin-right:10px; + padding:5px; +} + +dl.citelist dd { + margin:2px 0; + padding:5px 0; +} + +div.toc { + padding: 14px 25px; + background-color: #F6F6F6; + border: 1px solid #DDDDDD; + border-radius: 7px 7px 7px 7px; + float: right; + height: auto; + margin: 0 20px 10px 10px; + width: 200px; +} + +div.toc li { + background: url("bdwn.png") no-repeat scroll 0 5px transparent; + font: 10px/1.2 Verdana,DejaVu Sans,Geneva,sans-serif; + margin-top: 5px; + padding-left: 10px; + padding-top: 2px; +} + +div.toc h3 { + font: bold 12px/1.2 Arial,FreeSans,sans-serif; + border-bottom: 0 none; + color: #606060; + margin: 0; +} + +div.toc ul { + list-style: none outside none; + border: medium none; + padding: 0px; +} + +div.toc li.level1 { + margin-left: 0px; +} + +div.toc li.level2 { + margin-left: 15px; +} + +div.toc li.level3 { + margin-left: 30px; +} + +div.toc li.level4 { + margin-left: 45px; +} + +@media print +{ + #top { display: none; } + #side-nav { display: none; } + #nav-path { display: none; } + body { overflow:visible; } + h1, h2, h3, h4, h5, h6 { page-break-after: avoid; } + .summary { display: none; } + .memitem { page-break-inside: avoid; } + #doc-content + { + margin-left:0 !important; + height:auto !important; + width:auto !important; + overflow:inherit; + display:inline; + } + pre.fragment + { + overflow: visible; + text-wrap: unrestricted; + white-space: -moz-pre-wrap; /* Moz */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: pre-wrap; /* CSS3 */ + word-wrap: break-word; /* IE 5.5+ */ + } +} + diff --git a/ump_receiver_callbacks/c/ump_receiver_callbacks.c b/ump_receiver_callbacks/c/ump_receiver_callbacks.c index 2a68fec..c18bca0 100644 --- a/ump_receiver_callbacks/c/ump_receiver_callbacks.c +++ b/ump_receiver_callbacks/c/ump_receiver_callbacks.c @@ -1,4 +1,23 @@ -/* ump_receiver_callbacks.c - http://ultramessaging.github.io/UMExamples */ +/* ump_receiver_callbacks.c - see http://ultramessaging.github.io/UMExamples/ump_receiver_callbacks/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include@@ -17,18 +36,17 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: printf("DATA [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, @@ -36,9 +54,11 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); break; case LBM_MSG_REQUEST: - printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, - ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), - ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); + printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, + msg->source, msg->sequence_number, + ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), + ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), + (unsigned int)msg->len); break; case LBM_MSG_UNRECOVERABLE_LOSS: printf("[%s][%s][%x], LOST\n", msg->topic_name, msg->source, msg->sequence_number); @@ -76,7 +96,7 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) break; } case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: - { + { lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", msg->topic_name, msg->source, reg->sequence_number, reg->flags); @@ -116,15 +136,15 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } return 0; -} +} /* rcv_handle_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -143,11 +163,12 @@ main() /* Create receiver for receiving request and sending response */ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); + /* Wait forever (or until control-c). */ while (1) { } err = lbm_rcv_delete(rcv); @@ -160,4 +181,6 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif -} /* main */ + + return 0; +} /* main */ diff --git a/ump_receiver_callbacks/c/ump_receiver_callbacks.sldoc.html b/ump_receiver_callbacks/c/ump_receiver_callbacks.sldoc.html index aaf146c..fd5082a 100644 --- a/ump_receiver_callbacks/c/ump_receiver_callbacks.sldoc.html +++ b/ump_receiver_callbacks/c/ump_receiver_callbacks.sldoc.html @@ -23,16 +23,16 @@ Context/Receiver Create
is the callback function that will handle all the receiver callback events.-00140 /* Initialize context atrributes and create context */ -00141 err = lbm_context_create(&ctx, NULL, NULL, NULL); -00142 EX_LBM_CHK(err); -00143 -00144 /* Create receiver for receiving request and sending response */ -00145 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); -00146 EX_LBM_CHK(err); -00147 -00148 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); -00149 EX_LBM_CHK(err); +00160 /* Initialize context atrributes and create context */ +00161 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00162 EX_LBM_CHK(err); +00163 +00164 /* Create receiver for receiving request and sending response */ +00165 err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); +00166 EX_LBM_CHK(err); +00167 +00168 err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); +00169 EX_LBM_CHK(err);@@ -51,11 +51,11 @@Message Data Callback (LBM_MSG_DATA)
can be skipped. However, it would be useful to have the ability to enable logging as part of some kind of application debug mode.-00033 case LBM_MSG_DATA: -00034 printf("DATA [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, -00035 ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), -00036 ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); -00037 break; +00051 case LBM_MSG_DATA: +00052 printf("DATA [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, +00053 ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), +00054 ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); +00055 break;@@ -63,11 +63,13 @@Request Message (LBM_MSG_REQUEST)
Similar to data messages above, the only real difference being that these messages can be responded to via the API.
-00038 case LBM_MSG_REQUEST: -00039 printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, -00040 ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), -00041 ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); -00042 break; +00056 case LBM_MSG_REQUEST: +00057 printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, +00058 msg->source, msg->sequence_number, +00059 ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), +00060 ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), +00061 (unsigned int)msg->len); +00062 break;@@ -78,9 +80,9 @@Unrecoverable Loss (LBM_MSG_UNRECOVERABLE_LOSS)
The source information will identify the source publishing the messages that have been lost.-00043 case LBM_MSG_UNRECOVERABLE_LOSS: -00044 printf("[%s][%s][%x], LOST\n", msg->topic_name, msg->source, msg->sequence_number); -00045 break; +00063 case LBM_MSG_UNRECOVERABLE_LOSS: +00064 printf("[%s][%s][%x], LOST\n", msg->topic_name, msg->source, msg->sequence_number); +00065 break;@@ -91,9 +93,9 @@Unrecoverable Loss Burst (LBM_MSG_UNRECOVERABLE_LOSS_BURST)
See sample handle_burst for more information on handling burst loss-00046 case LBM_MSG_UNRECOVERABLE_LOSS_BURST: -00047 printf("[%s][%s][%x], LOST BURST\n", msg->topic_name, msg->source, msg->sequence_number); -00048 break; +00066 case LBM_MSG_UNRECOVERABLE_LOSS_BURST: +00067 printf("[%s][%s][%x], LOST BURST\n", msg->topic_name, msg->source, msg->sequence_number); +00068 break;@@ -103,9 +105,9 @@Beginning of Transport Session (LBM_MSG_BOS)
source information.-00049 case LBM_MSG_BOS: -00050 printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); -00051 break; +00069 case LBM_MSG_BOS: +00070 printf("[%s][%s], Beginning of Transport Session\n", msg->topic_name, msg->source); +00071 break;@@ -114,9 +116,9 @@End of Transport Session (LBM_MSG_EOS)
be logged with the same information as BOS.-00052 case LBM_MSG_EOS: -00053 printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); -00054 break; +00072 case LBM_MSG_EOS: +00073 printf("[%s][%s], End of Transport Session\n", msg->topic_name, msg->source); +00074 break;@@ -135,9 +137,9 @@No Source Notification (LBM_MSG_NO_SOURCE_NOTIFICATION)
Logging this callback is entirely up to the developer, however it could also be useful when trying to debug connectivity issues.-00055 case LBM_MSG_NO_SOURCE_NOTIFICATION: -00056 printf("[%s], no sources found for topic\n", msg->topic_name); -00057 break; +00075 case LBM_MSG_NO_SOURCE_NOTIFICATION: +00076 printf("[%s], no sources found for topic\n", msg->topic_name); +00077 break;@@ -146,9 +148,9 @@UMP Registration Error (LBM_MSG_UME_REGISTRATION_ERROR)
name and error string provided in the callback.-00058 case LBM_MSG_UME_REGISTRATION_ERROR: -00059 printf("[%s][%s] UME registration error: %s\n", msg->topic_name, msg->source, msg->data); -00060 break; +00078 case LBM_MSG_UME_REGISTRATION_ERROR: +00079 printf("[%s][%s] UME registration error: %s\n", msg->topic_name, msg->source, msg->data); +00080 break;@@ -159,23 +161,23 @@UMP Registration Success (LBM_MSG_UME_REGISTRATION_SUCCESS_EX)
source and receiver RegID are useful for tracking those components in the store log and store web-monitor.-00061 case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: -00062 { -00063 lbm_msg_ume_registration_ex_t *reg = (lbm_msg_ume_registration_ex_t *)(msg->data); -00064 printf("[%s][%s] store %u: %s UME registration successful. SrcRegID %u RcvRegID %u. Flags %x ", -00065 msg->topic_name, msg->source, reg->store_index, reg->store, -00066 reg->src_registration_id, reg->rcv_registration_id, reg->flags); -00067 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD) -00068 printf("OLD[SQN %x] ", reg->sequence_number); -00069 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_NOCACHE) -00070 printf("NOCACHE "); -00071 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_RPP) -00072 printf("RPP "); -00073 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_SRC_SID) -00074 printf("Src Session ID 0x%" PRIx64 " ", reg->src_session_id); -00075 printf("\n"); -00076 break; -00077 } +00081 case LBM_MSG_UME_REGISTRATION_SUCCESS_EX: +00082 { +00083 lbm_msg_ume_registration_ex_t *reg = (lbm_msg_ume_registration_ex_t *)(msg->data); +00084 printf("[%s][%s] store %u: %s UME registration successful. SrcRegID %u RcvRegID %u. Flags %x ", +00085 msg->topic_name, msg->source, reg->store_index, reg->store, +00086 reg->src_registration_id, reg->rcv_registration_id, reg->flags); +00087 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD) +00088 printf("OLD[SQN %x] ", reg->sequence_number); +00089 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_NOCACHE) +00090 printf("NOCACHE "); +00091 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_RPP) +00092 printf("RPP "); +00093 if (reg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_SRC_SID) +00094 printf("Src Session ID 0x%" PRIx64 " ", reg->src_session_id); +00095 printf("\n"); +00096 break; +00097 }@@ -185,20 +187,20 @@UMP Registration Complete (LBM_MSG_UME_REGISTRATION_COMPLETE_EX)
and the consensus sequence number . as this is the first sequence number the receiver should consume going forward.-00078 case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: -00079 { -00080 lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); -00081 printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", -00082 msg->topic_name, msg->source, reg->sequence_number, reg->flags); -00083 if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_QUORUM) -00084 printf("QUORUM "); -00085 if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_RXREQMAX) -00086 printf("RXREQMAX "); -00087 if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_SRC_SID) -00088 printf("Src Session ID 0x%" PRIx64 " ", reg->src_session_id); -00089 printf("\n"); -00090 break; -00091 } +00098 case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: +00099 { +00100 lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); +00101 printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", +00102 msg->topic_name, msg->source, reg->sequence_number, reg->flags); +00103 if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_QUORUM) +00104 printf("QUORUM "); +00105 if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_RXREQMAX) +00106 printf("RXREQMAX "); +00107 if (reg->flags & LBM_MSG_UME_REGISTRATION_COMPLETE_EX_FLAG_SRC_SID) +00108 printf("Src Session ID 0x%" PRIx64 " ", reg->src_session_id); +00109 printf("\n"); +00110 break; +00111 }@@ -208,21 +210,21 @@UMP Deregistration Success (LBM_MSG_UME_DEREGISTRATION_SUCCESS_EX)
logged here.-00092 case LBM_MSG_UME_DEREGISTRATION_SUCCESS_EX: -00093 { -00094 lbm_msg_ume_deregistration_ex_t *dereg = (lbm_msg_ume_deregistration_ex_t *)(msg->data); -00095 printf("[%s][%s] store %u: %s UME deregistration successful. SrcRegID %u RcvRegID %u. Flags %x ", -00096 msg->topic_name, msg->source, dereg->store_index, dereg->store, -00097 dereg->src_registration_id, dereg->rcv_registration_id, dereg->flags); -00098 if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD) -00099 printf("OLD[SQN %x] ", dereg->sequence_number); -00100 if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_NOCACHE) -00101 printf("NOCACHE "); -00102 if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_RPP) -00103 printf("RPP "); -00104 printf("\n"); -00105 break; -00106 } +00112 case LBM_MSG_UME_DEREGISTRATION_SUCCESS_EX: +00113 { +00114 lbm_msg_ume_deregistration_ex_t *dereg = (lbm_msg_ume_deregistration_ex_t *)(msg->data); +00115 printf("[%s][%s] store %u: %s UME deregistration successful. SrcRegID %u RcvRegID %u. Flags %x ", +00116 msg->topic_name, msg->source, dereg->store_index, dereg->store, +00117 dereg->src_registration_id, dereg->rcv_registration_id, dereg->flags); +00118 if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_OLD) +00119 printf("OLD[SQN %x] ", dereg->sequence_number); +00120 if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_NOCACHE) +00121 printf("NOCACHE "); +00122 if (dereg->flags & LBM_MSG_UME_REGISTRATION_SUCCESS_EX_FLAG_RPP) +00123 printf("RPP "); +00124 printf("\n"); +00125 break; +00126 }@@ -231,9 +233,9 @@UMP Deregistration Complete (LBM_MSG_UME_DEREGISTRATION_COMPLETE_EX)
should be logged. Topic name and source information are sufficient for this callback.-00107 case LBM_MSG_UME_DEREGISTRATION_COMPLETE_EX: -00108 printf("[%s][%s] UME deregistration complete.\n", msg->topic_name, msg->source); -00109 break; +00127 case LBM_MSG_UME_DEREGISTRATION_COMPLETE_EX: +00128 printf("[%s][%s] UME deregistration complete.\n", msg->topic_name, msg->source); +00129 break;@@ -242,9 +244,9 @@UMP Registration Change (LBM_MSG_UME_REGISTRATION_CHANGE)
the message data should be printed here. The message data will have the change that has been made to registration.-00110 case LBM_MSG_UME_REGISTRATION_CHANGE: -00111 printf("[%s][%s] UME registration change: %s\n", msg->topic_name, msg->source, msg->data); -00112 break; +00130 case LBM_MSG_UME_REGISTRATION_CHANGE: +00131 printf("[%s][%s] UME registration change: %s\n", msg->topic_name, msg->source, msg->data); +00132 break;@@ -253,9 +255,9 @@Other
other callbacks that could be handled for UMP. However, new callbacks are added, so it's good in the event of a library upgrade.-00113 default: -00114 printf("Other event, type=%x\n", msg->type); -00115 break; +00133 default: +00134 printf("Other event, type=%x\n", msg->type); +00135 break;@@ -264,20 +266,20 @@Includes
are not necessary for Linux only applications-00003 #include <stdio.h> -00004 -00005 #if defined(_MSC_VER) -00006 /* Windows-only includes */ -00007 #include <winsock2.h> -00008 #define SLEEP(s) Sleep((s)*1000) -00009 #else -00010 /* Unix-only includes */ -00011 #include <stdlib.h> -00012 #include <unistd.h> -00013 #define SLEEP(s) sleep(s) -00014 #endif -00015 -00016 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 +00024 #if defined(_MSC_VER) +00025 /* Windows-only includes */ +00026 #include <winsock2.h> +00027 #define SLEEP(s) Sleep((s)*1000) +00028 #else +00029 /* Unix-only includes */ +00030 #include <stdlib.h> +00031 #include <unistd.h> +00032 #define SLEEP(s) sleep(s) +00033 #endif +00034 +00035 #include <lbm/lbm.h>@@ -285,16 +287,16 @@Windows Only
Windows applications must initialize the Winsock library to utilize sockets.
-00129 #if defined(_WIN32) -00130 /* windows-specific code */ -00131 WSADATA wsadata; -00132 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); -00133 if (wsStat != 0) -00134 { -00135 printf("line %d: wsStat=%d\n",__LINE__,wsStat); -00136 exit(1); -00137 } -00138 #endif +00149 #if defined(_WIN32) +00150 /* windows-specific code */ +00151 WSADATA wsadata; +00152 int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); +00153 if (wsStat != 0) +00154 { +00155 printf("line %d: wsStat=%d\n",__LINE__,wsStat); +00156 exit(1); +00157 } +00158 #endifdiff --git a/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc b/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc index dca10ca..e439fc8 100644 --- a/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc +++ b/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc @@ -1,4 +1,23 @@ -/* ump_receiver_callbacks.c - http://ultramessaging.github.io/UMExamples */ +/* ump_receiver_callbacks.c - see http://ultramessaging.github.io/UMExamples/ump_receiver_callbacks/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -19,18 +38,17 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { /* =semlit,block,data=*/ case LBM_MSG_DATA: @@ -41,9 +59,11 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) /* =semlit,endblock,data=*/ /* =semlit,block,request=*/ case LBM_MSG_REQUEST: - printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, - ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), - ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); + printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, + msg->source, msg->sequence_number, + ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), + ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), + (unsigned int)msg->len); break; /* =semlit,endblock,request=*/ /* =semlit,block,loss=*/ @@ -97,7 +117,7 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) /* =semlit,endblock,reg_success=*/ /* =semlit,block,reg_complete=*/ case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: - { + { lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", msg->topic_name, msg->source, reg->sequence_number, reg->flags); @@ -146,15 +166,15 @@ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) } return 0; -} +} /* rcv_handle_msg */ -main() + +int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + int err; /* =semlit,block,windows=*/ #if defined(_WIN32) @@ -176,12 +196,13 @@ main() /* Create receiver for receiving request and sending response */ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); /* =semlit,endblock,ctx_rcv_create=*/ + /* Wait forever (or until control-c). */ while (1) { } err = lbm_rcv_delete(rcv); @@ -194,4 +215,6 @@ main() /* Windows-specific cleanup overhead */ WSACleanup(); #endif -} /* main */ + + return 0; +} /* main */ diff --git a/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc.html b/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc.html index e109170..4e0e742 100644 --- a/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc.html +++ b/ump_receiver_callbacks/c/ump_receiver_callbacks_c.slsrc.html @@ -18,168 +18,210 @@ diff --git a/ump_src_failover/README.txt b/ump_src_failover/README.txt deleted file mode 100644 index 6a17087..0000000 --- a/ump_src_failover/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -# README.txt - this file must conform to a standard format. - -Summary=Example UMP source application that demonstrates how a persisted source can failover to a backup store - -Description= diff --git a/ump_src_failover/c/ump_src_failover.c b/ump_src_failover/c/ump_src_failover.c index 9ebb980..8266c3f 100644 --- a/ump_src_failover/c/ump_src_failover.c +++ b/ump_src_failover/c/ump_src_failover.c @@ -1,4 +1,23 @@ -/* ump_src_failover.c */ +/* ump_src_failover.c - see http://ultramessaging.github.io/UMExamples/ump_src_failover/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 00017 00018 00019 00020 00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 -00052 -00053 -00054 -00055 -00056 -00057 -00058 -00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 -00080 -00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 -00099 -00100 -00101 -00102 -00103 -00104 -00105 -00106 -00107 -00108 -00109 -00110 -00111 -00112 -00113 -00114 -00115 -00116 -00117 -00118 -00119 -00120 -00121 -00122 -00123 -00124 -00125 -00126 -00127 -00128 -00129 -00130 -00131 -00132 -00133 -00134 -00135 -00136 -00137 -00138 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 +00052 +00053 +00054 +00055 +00056 +00057 +00058 +00059 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 +00080 +00081 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 +00109 +00110 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 +00136 +00137 +00138 00139 -00140 -00141 -00142 -00143 -00144 -00145 -00146 -00147 -00148 -00149 -00150 -00151 -00152 -00153 -00154 -00155 -00156 -00157 -00158 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 +00148 +00149 +00150 +00151 +00152 +00153 +00154 +00155 +00156 +00157 +00158 00159 -00160 -00161 -00162 -00163 - /* ump_receiver_callbacks.c - http://ultramessaging.github.io/UMExamples */ +00160 +00161 +00162 +00163 +00164 +00165 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 +00181 +00182 +00183 +00184 +00185 +00186 + /* ump_receiver_callbacks.c - see http://ultramessaging.github.io/UMExamples/ump_receiver_callbacks/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> @@ -198,18 +240,17 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) + /* Callback used to handle request message for receiver */ int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { - int err; - switch (msg->type) { case LBM_MSG_DATA: printf("DATA [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, @@ -217,9 +258,11 @@ ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); break; case LBM_MSG_REQUEST: - printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, msg->source, msg->sequence_number, - ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), - ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), (unsigned int)msg->len); + printf("REQUEST [%s][%s][%d]%s%s, %u bytes\n", msg->topic_name, + msg->source, msg->sequence_number, + ((msg->flags & LBM_MSG_FLAG_UME_RETRANSMIT) ? "-RX-" : ""), + ((msg->flags & LBM_MSG_FLAG_OTR) ? "-OTR-" : ""), + (unsigned int)msg->len); break; case LBM_MSG_UNRECOVERABLE_LOSS: printf("[%s][%s][%x], LOST\n", msg->topic_name, msg->source, msg->sequence_number); @@ -257,7 +300,7 @@ break; } case LBM_MSG_UME_REGISTRATION_COMPLETE_EX: - { + { lbm_msg_ume_registration_complete_ex_t *reg = (lbm_msg_ume_registration_complete_ex_t *)(msg->data); printf("[%s][%s] UME registration complete. SQN %x. Flags %x ", msg->topic_name, msg->source, reg->sequence_number, reg->flags); @@ -297,15 +340,15 @@ } return 0; - } + } /* rcv_handle_msg */ - main() + + int main(int argc, char **argv) { - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ - lbm_topic_t *rtopic; /* Receiver Topic object */ - int err; /* Used for checking API return codes */ + lbm_context_t *ctx; /* Context object */ + lbm_rcv_t *rcv; /* Receive object: for subscribing to messages. */ + lbm_topic_t *rtopic; /* Receiver Topic object */ + int err; #if defined(_WIN32) /* windows-specific code */ @@ -324,11 +367,12 @@ /* Create receiver for receiving request and sending response */ err = lbm_rcv_topic_lookup(&rtopic, ctx, "test.topic", NULL); - EX_LBM_CHK(err); + EX_LBM_CHK(err); err = lbm_rcv_create(&rcv, ctx, rtopic, rcv_handle_msg, NULL, NULL); EX_LBM_CHK(err); + /* Wait forever (or until control-c). */ while (1) { } err = lbm_rcv_delete(rcv); @@ -341,7 +385,9 @@ /* Windows-specific cleanup overhead */ WSACleanup(); #endif - } /* main */ + + return 0; + } /* main */ #include @@ -24,11 +43,11 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* Store configurations */ @@ -47,11 +66,12 @@ typedef struct app_src_s { mode_type_e mode; } app_src_s; + /* Source event handler callback (passed into lbm_src_create()) */ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) { struct app_src_s *app_src = (struct app_src_s *)cd; - switch (event) { + switch (event) { /* Success event provided only for printing purposes */ case LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX: { @@ -59,7 +79,7 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) printf("UME store %u: %s registration success.\n", reg->store_index, reg->store); break; } - case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: + case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: { lbm_src_event_ume_registration_complete_ex_t *reg = (lbm_src_event_ume_registration_complete_ex_t *)ed; @@ -80,49 +100,59 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) } return 0; -} +} /* handle_src_event */ + int init_src(app_src_s *app_src) { - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_topic_t *topic; /* Topic object */ - int err; /* Used for checking API return codes */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + lbm_topic_t *topic; /* Topic object */ + int err; - err = lbm_src_topic_attr_create(&tattr); - EX_LBM_CHK(err); + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_CLEAR_STORE_CONFIG); EX_LBM_CHK(err); - /* Assuming there are stores running on the localhost */ - if (app_src->mode == PRIMARY) - err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); - else + /* Assuming there are stores running on the localhost */ + if (app_src->mode == PRIMARY) { + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); + EX_LBM_CHK(err); + } + else { err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_SECONDARY_STORE); - EX_LBM_CHK(err); + EX_LBM_CHK(err); + } - if (app_src->mode == PRIMARY) + if (app_src->mode == PRIMARY) { err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_PRIMARY_SESSION_ID); - else + EX_LBM_CHK(err); + } + else { err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_SECONDARY_SESSION_ID); - EX_LBM_CHK(err); + EX_LBM_CHK(err); + } - /* Need to set store behavior to Quorum-Consensus */ - err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); - EX_LBM_CHK(err); + /* Need to set store behavior to Quorum-Consensus */ + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); - EX_LBM_CHK(err); + err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); + EX_LBM_CHK(err); - err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); - EX_LBM_CHK(err); + err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); + EX_LBM_CHK(err); app_src->state = INIT; -} + + return 0; +} /* init_src */ + void failover_app_src(app_src_s *app_src) { - int err; /* Used for checking API return codes */ + int err; /* Delete the source */ err = lbm_src_delete(app_src->src); @@ -131,7 +161,8 @@ void failover_app_src(app_src_s *app_src) app_src->src = NULL; app_src->state = NOT_INIT; app_src->mode = BACKUP; -} +} /* failover_app_src */ + /* Provided simply for printing the state name */ const char* source_state(app_src_s *app_src) @@ -143,49 +174,47 @@ const char* source_state(app_src_s *app_src) case READY: return "READY"; case UNRESP: return "UNRESP"; } -} + return NULL; +} /* source_state */ + -main() +int main(int argc, char **argv) { - app_src_s app_src; /* App structure to track source */ - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ + app_src_s app_src; /* App structure to track source */ + lbm_context_t *ctx; /* Context object */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); app_src.state = NOT_INIT; app_src.mode = PRIMARY; app_src.ctx = ctx; - while(1) - { + while(1) + { /* Initialize the source if we're not initialized */ if (app_src.state == NOT_INIT) init_src(&app_src); if (app_src.state == READY) { - if (lbm_src_send(app_src.src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) - { + if (lbm_src_send(app_src.src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + { /* Assume EWOULDBLOCK and wait */ SLEEP_SEC(1); - } + } } else { @@ -203,5 +232,6 @@ main() } SLEEP_SEC(1); } - } -} + } + return 0; +} /* main */ diff --git a/ump_src_failover/c/ump_src_failover.sldoc.html b/ump_src_failover/c/ump_src_failover.sldoc.html index 6e79fb5..1b4e56a 100644 --- a/ump_src_failover/c/ump_src_failover.sldoc.html +++ b/ump_src_failover/c/ump_src_failover.sldoc.html @@ -46,10 +46,10 @@ Defining Store Configurations
configuration files.-00035 #define UMP_PRIMARY_STORE "127.0.0.1:29999" -00036 #define UMP_PRIMARY_SESSION_ID "100" -00037 #define UMP_SECONDARY_STORE "127.0.0.1:30000" -00038 #define UMP_SECONDARY_SESSION_ID "200" +00054 #define UMP_PRIMARY_STORE "127.0.0.1:29999" +00055 #define UMP_PRIMARY_SESSION_ID "100" +00056 #define UMP_SECONDARY_STORE "127.0.0.1:30000" +00057 #define UMP_SECONDARY_SESSION_ID "200"@@ -105,7 +105,7 @@Defining Store Configurations
defined as a global attribute:-00039 #define UMP_CLEAR_STORE_CONFIG "0.0.0.0:0" +00058 #define UMP_CLEAR_STORE_CONFIG "0.0.0.0:0"@@ -122,14 +122,14 @@Define a Custom Source Object
as store the pointer object to the source itself and the sources context-00041 typedef enum {NOT_INIT, INIT, READY, UNRESP} state_type_e; -00042 typedef enum {PRIMARY, BACKUP} mode_type_e; -00043 typedef struct app_src_s { -00044 lbm_context_t *ctx; -00045 lbm_src_t *src; -00046 state_type_e state; -00047 mode_type_e mode; -00048 } app_src_s; +00060 typedef enum {NOT_INIT, INIT, READY, UNRESP} state_type_e; +00061 typedef enum {PRIMARY, BACKUP} mode_type_e; +00062 typedef struct app_src_s { +00063 lbm_context_t *ctx; +00064 lbm_src_t *src; +00065 state_type_e state; +00066 mode_type_e mode; +00067 } app_src_s;@@ -137,11 +137,8 @@Create the Context
Standard UM code to initialize and create an LBM context:
-00166 err = lbm_context_attr_create(&cattr); -00167 EX_LBM_CHK(err); -00168 -00169 err = lbm_context_create(&ctx, cattr, NULL, NULL); -00170 EX_LBM_CHK(err); +00198 err = lbm_context_create(&ctx, NULL, NULL, NULL); +00199 EX_LBM_CHK(err);@@ -151,9 +148,9 @@Initializing the Customer Source Object
created within it:-00172 app_src.state = NOT_INIT; -00173 app_src.mode = PRIMARY; -00174 app_src.ctx = ctx; +00201 app_src.state = NOT_INIT; +00202 app_src.mode = PRIMARY; +00203 app_src.ctx = ctx;@@ -162,8 +159,8 @@Configuring the Stores and Creating the Source
the loop, the application intializes/creates a source:-00179 if (app_src.state == NOT_INIT) -00180 init_src(&app_src); +00208 if (app_src.state == NOT_INIT) +00209 init_src(&app_src);@@ -189,11 +186,11 @@Configuring the Stores and Creating the Source
to "0.0.0.0:0":-00091 err = lbm_src_topic_attr_create(&tattr); -00092 EX_LBM_CHK(err); -00093 -00094 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_CLEAR_STORE_CONFIG); -00095 EX_LBM_CHK(err); +00112 err = lbm_src_topic_attr_create(&tattr); +00113 EX_LBM_CHK(err); +00114 +00115 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_CLEAR_STORE_CONFIG); +00116 EX_LBM_CHK(err);@@ -201,31 +198,37 @@Configuring the Stores and Creating the Source
initialized to PRIMARY, so it'll use the primary stores and associated SessionID:-00098 if (app_src->mode == PRIMARY) -00099 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); -00100 else -00101 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_SECONDARY_STORE); -00102 EX_LBM_CHK(err); -00103 -00104 if (app_src->mode == PRIMARY) -00105 err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_PRIMARY_SESSION_ID); -00106 else -00107 err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_SECONDARY_SESSION_ID); -00108 EX_LBM_CHK(err); +00119 if (app_src->mode == PRIMARY) { +00120 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); +00121 EX_LBM_CHK(err); +00122 } +00123 else { +00124 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_SECONDARY_STORE); +00125 EX_LBM_CHK(err); +00126 } +00127 +00128 if (app_src->mode == PRIMARY) { +00129 err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_PRIMARY_SESSION_ID); +00130 EX_LBM_CHK(err); +00131 } +00132 else { +00133 err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_SECONDARY_SESSION_ID); +00134 EX_LBM_CHK(err); +00135 }Finally the sample sets the store behavior to use quorum/consensus and creates the source object:
-00111 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); -00112 EX_LBM_CHK(err); -00113 -00114 err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); -00115 EX_LBM_CHK(err); -00116 -00117 err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); -00118 EX_LBM_CHK(err); +00138 err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); +00139 EX_LBM_CHK(err); +00140 +00141 err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); +00142 EX_LBM_CHK(err); +00143 +00144 err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); +00145 EX_LBM_CHK(err);@@ -236,15 +239,15 @@Handling Source Events / Updating Source State
registration complete event is coded into the source event handler function, and the complete event should like this:-00062 case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: -00063 { -00064 lbm_src_event_ume_registration_complete_ex_t *reg = (lbm_src_event_ume_registration_complete_ex_t *)ed; -00065 -00066 printf("UME registration complete. SQN %x.\n", reg->sequence_number); -00067 -00068 app_src->state = READY; -00069 break; -00070 } +00082 case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: +00083 { +00084 lbm_src_event_ume_registration_complete_ex_t *reg = (lbm_src_event_ume_registration_complete_ex_t *)ed; +00085 +00086 printf("UME registration complete. SQN %x.\n", reg->sequence_number); +00087 +00088 app_src->state = READY; +00089 break; +00090 }@@ -253,15 +256,15 @@Handling Source Events / Updating Source State
is lost, the source state must be updated to note this change because it can no longer send messages:-00071 case LBM_SRC_EVENT_UME_STORE_UNRESPONSIVE: -00072 { -00073 const char *infostr = (const char *)ed; -00074 -00075 printf("UME store: %s\n", infostr); -00076 if (strstr(infostr, "quorum lost") != NULL) -00077 app_src->state = UNRESP; -00078 break; -00079 } +00091 case LBM_SRC_EVENT_UME_STORE_UNRESPONSIVE: +00092 { +00093 const char *infostr = (const char *)ed; +00094 +00095 printf("UME store: %s\n", infostr); +00096 if (strstr(infostr, "quorum lost") != NULL) +00097 app_src->state = UNRESP; +00098 break; +00099 }@@ -283,11 +286,11 @@Automatic Failover
So here is the sample application failing over once the main loop has detected the state as UNRESP:
-00194 if (app_src.state == UNRESP && app_src.mode == PRIMARY) -00195 { -00196 printf("Primary store unresponsive, failing over to backup\n"); -00197 failover_app_src(&app_src); -00198 } +00223 if (app_src.state == UNRESP && app_src.mode == PRIMARY) +00224 { +00225 printf("Primary store unresponsive, failing over to backup\n"); +00226 failover_app_src(&app_src); +00227 }@@ -300,28 +303,28 @@Delete the Source and Reset State
First, the source gets deleted:
-00128 err = lbm_src_delete(app_src->src); -00129 EX_LBM_CHK(err); +00158 err = lbm_src_delete(app_src->src); +00159 EX_LBM_CHK(err);Then the state gets updated to NOT_INIT, and the mode set to backup so the backup stores can be configured upon initialization:
-00131 app_src->src = NULL; -00132 app_src->state = NOT_INIT; -00133 app_src->mode = BACKUP; +00161 app_src->src = NULL; +00162 app_src->state = NOT_INIT; +00163 app_src->mode = BACKUP;In the event that the backup store goes unresponsive, the sample application is simply coded to exit at this point:
-00199 else if (app_src.state == UNRESP && app_src.mode == BACKUP) -00200 { -00201 printf("Backup store unresponsive. Exiting\n"); -00202 exit(1); -00203 } +00228 else if (app_src.state == UNRESP && app_src.mode == BACKUP) +00229 { +00230 printf("Backup store unresponsive. Exiting\n"); +00231 exit(1); +00232 }@@ -342,21 +345,21 @@Includes
Include files for this application. Notice the Windows specific include files - these are not necessary for Linux only applications
-00003 #include <stdio.h> -00004 #include <string.h> -00005 -00006 #if defined(_MSC_VER) -00007 /* Windows-only includes */ -00008 #include <winsock2.h> -00009 #define SLEEP(s) Sleep((s)*1000) -00010 #else -00011 /* Unix-only includes */ -00012 #include <stdlib.h> -00013 #include <unistd.h> -00014 #define SLEEP(s) sleep(s) -00015 #endif -00016 -00017 #include <lbm/lbm.h> +00022 #include <stdio.h> +00023 #include <string.h> +00024 +00025 #if defined(_MSC_VER) +00026 /* Windows-only includes */ +00027 #include <winsock2.h> +00028 #define SLEEP(s) Sleep((s)*1000) +00029 #else +00030 /* Unix-only includes */ +00031 #include <stdlib.h> +00032 #include <unistd.h> +00033 #define SLEEP(s) sleep(s) +00034 #endif +00035 +00036 #include <lbm/lbm.h>@@ -365,11 +368,11 @@Sleep helper function
sleep() for any number of seconds.-00019 #if defined(_WIN32) -00020 # define SLEEP_SEC(x) Sleep((x)*1000) -00021 #else -00022 # define SLEEP_SEC(x) sleep(x) -00023 #endif +00038 #if defined(_WIN32) +00039 # define SLEEP_SEC(x) Sleep((x)*1000) +00040 #else +00041 # define SLEEP_SEC(x) sleep(x) +00042 #endifdiff --git a/ump_src_failover/c/ump_src_failover_c.slsrc b/ump_src_failover/c/ump_src_failover_c.slsrc index baf56e7..73ea8a5 100644 --- a/ump_src_failover/c/ump_src_failover_c.slsrc +++ b/ump_src_failover/c/ump_src_failover_c.slsrc @@ -1,4 +1,23 @@ -/* ump_src_failover.c */ +/* ump_src_failover.c - see http://ultramessaging.github.io/UMExamples/ump_src_failover/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ /* =semlit,block,includes=*/ #include@@ -29,11 +48,11 @@ /* Example error checking macro. Include after each UM call. */ /* =semlit,block,errors=*/ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* =semlit,endblock,errors=*/ @@ -59,11 +78,12 @@ typedef struct app_src_s { } app_src_s; /* =semlit,endblock,app_src_struct=*/ + /* Source event handler callback (passed into lbm_src_create()) */ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) { struct app_src_s *app_src = (struct app_src_s *)cd; - switch (event) { + switch (event) { /* Success event provided only for printing purposes */ case LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX: { @@ -72,7 +92,7 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) break; } /* =semlit,block,reg_complete=*/ - case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: + case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: { lbm_src_event_ume_registration_complete_ex_t *reg = (lbm_src_event_ume_registration_complete_ex_t *)ed; @@ -100,57 +120,67 @@ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) } return 0; -} +} /* handle_src_event */ + int init_src(app_src_s *app_src) { - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_topic_t *topic; /* Topic object */ - int err; /* Used for checking API return codes */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + lbm_topic_t *topic; /* Topic object */ + int err; - /* =semlit,block,init_source_attr=*/ - err = lbm_src_topic_attr_create(&tattr); - EX_LBM_CHK(err); + /* =semlit,block,init_source_attr=*/ + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_CLEAR_STORE_CONFIG); EX_LBM_CHK(err); /* =semlit,endblock,init_source_attr=*/ - /* Assuming there are stores running on the localhost */ + /* Assuming there are stores running on the localhost */ /* =semlit,block,set_store=*/ - if (app_src->mode == PRIMARY) - err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); - else + if (app_src->mode == PRIMARY) { + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); + EX_LBM_CHK(err); + } + else { err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_SECONDARY_STORE); - EX_LBM_CHK(err); + EX_LBM_CHK(err); + } - if (app_src->mode == PRIMARY) + if (app_src->mode == PRIMARY) { err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_PRIMARY_SESSION_ID); - else + EX_LBM_CHK(err); + } + else { err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_SECONDARY_SESSION_ID); - EX_LBM_CHK(err); + EX_LBM_CHK(err); + } /* =semlit,endblock,set_store=*/ - /* Need to set store behavior to Quorum-Consensus */ + /* Need to set store behavior to Quorum-Consensus */ /* =semlit,block,complete_init=*/ - err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); - EX_LBM_CHK(err); + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); + EX_LBM_CHK(err); - err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); - EX_LBM_CHK(err); + err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); + EX_LBM_CHK(err); - err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); - EX_LBM_CHK(err); - /* =semlit,endblock,complete_init=*/ + err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); + EX_LBM_CHK(err); + /* =semlit,endblock,complete_init=*/ /* =semlit,block,update_state_init=*/ app_src->state = INIT; /* =semlit,endblock,update_state_init=*/ -} + + return 0; +} /* init_src */ + void failover_app_src(app_src_s *app_src) { - int err; /* Used for checking API return codes */ + int err; /* Delete the source */ /* =semlit,block,delete_src=*/ @@ -163,7 +193,8 @@ void failover_app_src(app_src_s *app_src) app_src->state = NOT_INIT; app_src->mode = BACKUP; /* =semlit,endblock,update_state_not_init=*/ -} +} /* failover_app_src */ + /* Provided simply for printing the state name */ /* =semlit,block,print_state_helper=*/ @@ -176,36 +207,34 @@ const char* source_state(app_src_s *app_src) case READY: return "READY"; case UNRESP: return "UNRESP"; } -} + return NULL; +} /* source_state */ /* =semlit,endblock,print_state_helper=*/ -main() + +int main(int argc, char **argv) { - /* =semlit,block,variables=*/ - app_src_s app_src; /* App structure to track source */ - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ - /* =semlit,endblock,variables=*/ + /* =semlit,block,variables=*/ + app_src_s app_src; /* App structure to track source */ + lbm_context_t *ctx; /* Context object */ + int err; + /* =semlit,endblock,variables=*/ #if defined(_WIN32) - /* 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); - } + /* 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 - /* =semlit,block,init_create_context=*/ - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + /* =semlit,block,init_create_context=*/ + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); - /* =semlit,endblock,init_create_context=*/ + /* =semlit,endblock,init_create_context=*/ /* =semlit,block,init_app_src=*/ app_src.state = NOT_INIT; @@ -213,25 +242,25 @@ main() app_src.ctx = ctx; /* =semlit,endblock,init_app_src=*/ - /* =semlit,block,main_send_loop=*/ - while(1) - /* =semlit,endblock,main_send_loop=*/ - { + /* =semlit,block,main_send_loop=*/ + while(1) + /* =semlit,endblock,main_send_loop=*/ + { /* Initialize the source if we're not initialized */ /* =semlit,block,start_init=*/ if (app_src.state == NOT_INIT) init_src(&app_src); /* =semlit,endblock,start_init=*/ - /* =semlit,block,src_send=*/ + /* =semlit,block,src_send=*/ if (app_src.state == READY) /* =semlit,endblock,src_send=*/ { - if (lbm_src_send(app_src.src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) - { + if (lbm_src_send(app_src.src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + { /* Assume EWOULDBLOCK and wait */ SLEEP_SEC(1); - } + } } else { @@ -253,5 +282,6 @@ main() /* =semlit,endblock,backup_unresp=*/ SLEEP_SEC(1); } - } -} + } + return 0; +} /* main */ diff --git a/ump_src_failover/c/ump_src_failover_c.slsrc.html b/ump_src_failover/c/ump_src_failover_c.slsrc.html index b8ecbe2..082a0d8 100644 --- a/ump_src_failover/c/ump_src_failover_c.slsrc.html +++ b/ump_src_failover/c/ump_src_failover_c.slsrc.html @@ -18,189 +18,189 @@
00001 00002 -00003 -00004 -00005 -00006 -00007 -00008 -00009 -00010 -00011 -00012 -00013 -00014 -00015 -00016 -00017 +00003 +00004 +00005 +00006 +00007 +00008 +00009 +00010 +00011 +00012 +00013 +00014 +00015 +00016 +00017 00018 -00019 -00020 -00021 -00022 -00023 -00024 -00025 -00026 -00027 -00028 -00029 -00030 -00031 -00032 -00033 -00034 -00035 -00036 -00037 -00038 -00039 -00040 -00041 -00042 -00043 -00044 -00045 -00046 -00047 -00048 -00049 -00050 -00051 +00019 +00020 +00021 +00022 +00023 +00024 +00025 +00026 +00027 +00028 +00029 +00030 +00031 +00032 +00033 +00034 +00035 +00036 +00037 +00038 +00039 +00040 +00041 +00042 +00043 +00044 +00045 +00046 +00047 +00048 +00049 +00050 +00051 00052 00053 -00054 -00055 -00056 -00057 -00058 +00054 +00055 +00056 +00057 +00058 00059 -00060 -00061 -00062 -00063 -00064 -00065 -00066 -00067 -00068 -00069 -00070 -00071 -00072 -00073 -00074 -00075 -00076 -00077 -00078 -00079 +00060 +00061 +00062 +00063 +00064 +00065 +00066 +00067 +00068 +00069 +00070 +00071 +00072 +00073 +00074 +00075 +00076 +00077 +00078 +00079 00080 00081 -00082 -00083 -00084 -00085 -00086 -00087 -00088 -00089 -00090 -00091 -00092 -00093 -00094 -00095 -00096 -00097 -00098 -00099 -00100 -00101 -00102 -00103 -00104 -00105 -00106 -00107 -00108 +00082 +00083 +00084 +00085 +00086 +00087 +00088 +00089 +00090 +00091 +00092 +00093 +00094 +00095 +00096 +00097 +00098 +00099 +00100 +00101 +00102 +00103 +00104 +00105 +00106 +00107 +00108 00109 00110 -00111 -00112 -00113 -00114 -00115 -00116 -00117 -00118 -00119 -00120 -00121 -00122 -00123 -00124 -00125 -00126 -00127 -00128 -00129 -00130 -00131 -00132 -00133 -00134 -00135 +00111 +00112 +00113 +00114 +00115 +00116 +00117 +00118 +00119 +00120 +00121 +00122 +00123 +00124 +00125 +00126 +00127 +00128 +00129 +00130 +00131 +00132 +00133 +00134 +00135 00136 -00137 -00138 -00139 -00140 -00141 -00142 -00143 -00144 -00145 -00146 -00147 +00137 +00138 +00139 +00140 +00141 +00142 +00143 +00144 +00145 +00146 +00147 00148 00149 -00150 -00151 -00152 -00153 +00150 +00151 +00152 +00153 00154 00155 00156 00157 -00158 -00159 +00158 +00159 00160 -00161 -00162 -00163 +00161 +00162 +00163 00164 00165 -00166 -00167 -00168 -00169 -00170 -00171 -00172 -00173 -00174 -00175 -00176 -00177 -00178 -00179 -00180 +00166 +00167 +00168 +00169 +00170 +00171 +00172 +00173 +00174 +00175 +00176 +00177 +00178 +00179 +00180 00181 -00182 -00183 -00184 -00185 +00182 +00183 +00184 +00185 00186 00187 00188 @@ -209,21 +209,70 @@ 00191 00192 00193 -00194 -00195 -00196 -00197 -00198 -00199 -00200 -00201 -00202 -00203 +00194 +00195 +00196 +00197 +00198 +00199 +00200 +00201 +00202 +00203 00204 -00205 +00205 00206 00207 - /* ump_src_failover.c */ +00208 +00209 +00210 +00211 +00212 +00213 +00214 +00215 +00216 +00217 +00218 +00219 +00220 +00221 +00222 +00223 +00224 +00225 +00226 +00227 +00228 +00229 +00230 +00231 +00232 +00233 +00234 +00235 +00236 +00237 + /* ump_src_failover.c - see http://ultramessaging.github.io/UMExamples/ump_src_failover/c/index.html + * + * Copyright (c) 2005-2017 Informatica Corporation. All Rights Reserved. + * Permission is granted to licensees to use + * or alter this software for any purpose, including commercial applications, + * according to the terms laid out in the Software License Agreement. + * + * This source code example is provided by Informatica for educational + * and evaluation purposes only. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INFORMATICA DISCLAIMS ALL WARRANTIES + * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF + * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR + * PURPOSE. INFORMATICA DOES NOT WARRANT THAT USE OF THE SOFTWARE WILL BE + * UNINTERRUPTED OR ERROR-FREE. INFORMATICA SHALL NOT, UNDER ANY CIRCUMSTANCES, BE + * LIABLE TO LICENSEE FOR LOST PROFITS, CONSEQUENTIAL, INCIDENTAL, SPECIAL OR + * INDIRECT DAMAGES ARISING OUT OF OR RELATED TO THIS AGREEMENT OR THE + * TRANSACTIONS CONTEMPLATED HEREUNDER, EVEN IF INFORMATICA HAS BEEN APPRISED OF + * THE LIKELIHOOD OF SUCH DAMAGES. + */ #include <stdio.h> #include <string.h> @@ -249,11 +298,11 @@ /* Example error checking macro. Include after each UM call. */ #define EX_LBM_CHK(err) do { \ - if ((err) < 0) { \ - fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ - __FILE__, __LINE__, lbm_errmsg()); \ - exit(1); \ - } \ + if ((err) < 0) { \ + fprintf(stderr, "%s:%d, lbm error: '%s'\n", \ + __FILE__, __LINE__, lbm_errmsg()); \ + exit(1); \ + } \ } while (0) /* Store configurations */ @@ -272,11 +321,12 @@ mode_type_e mode; } app_src_s; + /* Source event handler callback (passed into lbm_src_create()) */ int handle_src_event(lbm_src_t *src, int event, void *ed, void *cd) { struct app_src_s *app_src = (struct app_src_s *)cd; - switch (event) { + switch (event) { /* Success event provided only for printing purposes */ case LBM_SRC_EVENT_UME_REGISTRATION_SUCCESS_EX: { @@ -284,7 +334,7 @@ printf("UME store %u: %s registration success.\n", reg->store_index, reg->store); break; } - case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: + case LBM_SRC_EVENT_UME_REGISTRATION_COMPLETE_EX: { lbm_src_event_ume_registration_complete_ex_t *reg = (lbm_src_event_ume_registration_complete_ex_t *)ed; @@ -305,49 +355,59 @@ } return 0; - } + } /* handle_src_event */ + int init_src(app_src_s *app_src) { - lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ - lbm_topic_t *topic; /* Topic object */ - int err; /* Used for checking API return codes */ + lbm_src_topic_attr_t * tattr; /* Source topic attribute object */ + lbm_topic_t *topic; /* Topic object */ + int err; - err = lbm_src_topic_attr_create(&tattr); - EX_LBM_CHK(err); + err = lbm_src_topic_attr_create(&tattr); + EX_LBM_CHK(err); err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_CLEAR_STORE_CONFIG); EX_LBM_CHK(err); - /* Assuming there are stores running on the localhost */ - if (app_src->mode == PRIMARY) - err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); - else + /* Assuming there are stores running on the localhost */ + if (app_src->mode == PRIMARY) { + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_PRIMARY_STORE); + EX_LBM_CHK(err); + } + else { err = lbm_src_topic_attr_str_setopt(tattr, "ume_store", UMP_SECONDARY_STORE); EX_LBM_CHK(err); + } - if (app_src->mode == PRIMARY) + if (app_src->mode == PRIMARY) { err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_PRIMARY_SESSION_ID); - else + EX_LBM_CHK(err); + } + else { err = lbm_src_topic_attr_str_setopt(tattr, "ume_session_id", UMP_SECONDARY_SESSION_ID); - EX_LBM_CHK(err); - - /* Need to set store behavior to Quorum-Consensus */ - err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); EX_LBM_CHK(err); + } - err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); - EX_LBM_CHK(err); + /* Need to set store behavior to Quorum-Consensus */ + err = lbm_src_topic_attr_str_setopt(tattr, "ume_store_behavior", "qc"); + EX_LBM_CHK(err); - err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); - EX_LBM_CHK(err); + err = lbm_src_topic_alloc(&topic, app_src->ctx, "test.topic", tattr); + EX_LBM_CHK(err); + + err = lbm_src_create(&(app_src->src), app_src->ctx, topic, handle_src_event, app_src, NULL); + EX_LBM_CHK(err); app_src->state = INIT; - } + + return 0; + } /* init_src */ + void failover_app_src(app_src_s *app_src) { - int err; /* Used for checking API return codes */ + int err; /* Delete the source */ err = lbm_src_delete(app_src->src); @@ -356,7 +416,8 @@ app_src->src = NULL; app_src->state = NOT_INIT; app_src->mode = BACKUP; - } + } /* failover_app_src */ + /* Provided simply for printing the state name */ const char* source_state(app_src_s *app_src) @@ -368,49 +429,47 @@ case READY: return "READY"; case UNRESP: return "UNRESP"; } - } + return NULL; + } /* source_state */ - main() + + int main(int argc, char **argv) { - app_src_s app_src; /* App structure to track source */ - lbm_context_t *ctx; /* Context object */ - lbm_context_attr_t * cattr; /* Context attribute object */ - int err; /* Used for checking API return codes */ + app_src_s app_src; /* App structure to track source */ + lbm_context_t *ctx; /* Context object */ + int err; #if defined(_WIN32) - /* 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); - } + /* 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 - err = lbm_context_attr_create(&cattr); - EX_LBM_CHK(err); - - err = lbm_context_create(&ctx, cattr, NULL, NULL); + err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); app_src.state = NOT_INIT; app_src.mode = PRIMARY; app_src.ctx = ctx; - while(1) - { + while(1) + { /* Initialize the source if we're not initialized */ if (app_src.state == NOT_INIT) init_src(&app_src); if (app_src.state == READY) { - if (lbm_src_send(app_src.src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) - { + if (lbm_src_send(app_src.src, "test", 4, LBM_SRC_NONBLOCK) == LBM_FAILURE) + { /* Assume EWOULDBLOCK and wait */ SLEEP_SEC(1); - } + } } else { @@ -428,8 +487,9 @@ } SLEEP_SEC(1); } - } - } + } + return 0; + } /* main */