Documentation of the Test-Client-Server tool used for example.test
.
The Naming-Test-Tool tool is used to test the name-resolution-feature of ccmqmsgque.
To perform the test 2 tools are used, the testclient and the testserver.
testclient | This tool creates multiple parent and child client-context, all using a |
testserver | This tool listen on the service GTCX and return the unique identification pattern of the server-context in duty. |
All context created, 8x client and 8x server, are connected using the ccmqmsgque protocoll and build together a flat structure.
The GOAL for this setup is:
/** * @file NHI1/example/cc/testclient.cc * @brief testclient.cc - 01 Nov 2024 - aotto1968 * @copyright (C) NHI - #1 - Project - Group * This software has NO permission to copy, * please contact AUTHOR for additional information * @version 8dbe2fd9f53d3983fa80dd80ddcb8f254b666391 * @date Fri Nov 1 22:34:52 2024 +0100 * @author aotto1968 <aotto1968@t-online.de> */ /* LABEL-START */ #include "debug_mq.h" #include "LibMqMsgque_cc.hh" /* LABEL-END */ #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <libgen.h> #include <limits.h> #include <stdio.h> #include "msgque_config.h" using namespace std; using namespace ccmqmsgque; static string Get( MqContextC& ctx) { MkBufferC RET; ctx.SendSTART(); ctx.SendEND_AND_WAIT("GTCX", MK_TIMEOUT_USER); RET.Reset(); RET.AppendSTR(ctx.ConfigGetName()); RET.AppendSTR("+"); RET.AppendSTR(ctx.ReadSTR()); RET.AppendSTR(ctx.ReadSTR()); RET.AppendSTR(ctx.ReadSTR()); RET.AppendSTR(ctx.ReadSTR()); RET.AppendSTR(ctx.ReadSTR()); RET.AppendSTR(ctx.ReadSTR()); return RET.GetSTR(); } int MK_CDECL main(int argc, MK_STRN argv[]) { MqMsgque::Setup(); // find abs path :-) FILE *fp; char abs_exe_path[PATH_MAX]; // build command strcpy (abs_exe_path, "/usr/bin/which "); strcat (abs_exe_path, argv[0]); /* Open the command for reading. */ fp = popen(abs_exe_path, "r"); if (fp == NULL) { printf("Failed to run command\n" ); exit(1); } /* Read the output a line at a time - output it. */ if (fgets(abs_exe_path, sizeof(abs_exe_path), fp) == NULL) { printf("Failed to extract path\n" ); exit(1); } /* close */ pclose(fp); MK_STRN tstr = strdup(dirname(abs_exe_path)); strcpy (abs_exe_path, tstr); MkSysFree(tstr); // setup the clients MkBufferListC t1 = {argv[0], "--prefix", "c", "--postfix", "1", NULL}; for (int i=1; i<argc; i++) t1.AppendSTR(argv[i]); static MqContextC c0, c00, c01, c000, c1, c10, c100, c101; try { // create the "LINK" #if defined(META_IS_POSIX) MK_STRN server = strcat(abs_exe_path,"/testserver"); #elif defined(META_IS_WINDOWS) MK_STRN server = strcat(abs_exe_path,"/testserver.exe"); #else #error "META_IS_POSIX or META_IS_WINDOWS is missing" #endif c0.LinkCreate(MkBufferListC { argv[0], "--prefix", "c", "--postfix", "0", "--debug", getenv("TS_DEBUG"), "@", server, "--prefix", "s", NULL }); c00.LinkCreateChild( c0, MkBufferListC {"--postfix", "00", NULL}); c01.LinkCreateChild( c0, MkBufferListC {"--postfix", "01", NULL}); c000.LinkCreateChild( c00, MkBufferListC {"--postfix", "000", NULL}); c1.LinkCreate(t1); c10.LinkCreateChild( c1, MkBufferListC {"--postfix", "10", NULL}); c100.LinkCreateChild( c10, MkBufferListC {"--postfix", "100", NULL}); c101.LinkCreateChild( c10, MkBufferListC {"--postfix", "101", NULL}); // do the tests cout << Get(c0) << endl << Get(c00) << endl << Get(c01) << endl << Get(c000) << endl; cout << Get(c1) << endl << Get(c10) << endl << Get(c100) << endl << Get(c101) << endl; } catch (const std::exception& e) { c1.ErrorCatch(e); } // do the cleanup c1.Exit(); }
/** * @file NHI1/example/cc/testserver.cc * @brief testserver.cc - 12 Nov 2024 - aotto1968 * @copyright (C) NHI - #1 - Project - Group * This software has NO permission to copy, * please contact AUTHOR for additional information * @version 478c13192af70c38a452c665c8243fd6902efb63 * @date Tue Nov 12 14:49:07 2024 +0100 * @author aotto1968 <aotto1968@t-online.de> */ /* LABEL-START */ #include "debug_mq.h" #include "LibMqMsgque_cc.hh" /* LABEL-END */ using namespace ccmqmsgque; class testserver : public MqContextC, public MqServerSetupIF { friend class MqFactoryCT<testserver>; private: testserver(MK_TYP const typ, MqContextC* tmpl=NULL) : MqContextC(typ, tmpl) {} private: void GTCX () { SendSTART(); SendI32(LinkGetCtxId()); SendSTR("+"); if (LinkIsParent()) { SendI32(-1); } else { SendI32(LinkGetParent()->LinkGetCtxId()); } SendSTR("+"); SendSTR(ConfigGetName()); SendSTR(":"); SendRETURN(); } void ServerSetup() { ServiceCreate("GTCX", MqServiceICB(&testserver::GTCX)); } }; int MK_CDECL main (int argc, MK_STRN argv[]) { MqMsgque::Setup(); testserver *ctx = MqFactoryCT<testserver>::Add("testserver")->New(); try { ctx->LinkCreate(MkBufferListC {argc, argv}); ctx->ProcessEvent (MQ_WAIT_FOREVER); } catch (const std::exception& e) { ctx->ErrorCatch(e); } ctx->Exit (); }