theLink 10.0
Loading...
Searching...
No Matches
Filter4.cc
Go to the documentation of this file.
1
9/* LABEL-START */
10
11#include "debug_mq.h"
12#include "LibMqMsgque_cc.hh"
13
14/* LABEL-END */
15
16#define META_CONTEXT_S hdl
17
18#include <queue>
19#include <stdexcept>
20#include <stdlib.h>
21#include <stdio.h>
22
23using namespace std;
24using namespace ccmqmsgque;
25
26class Filter4 : public MqContextC, public MqServerSetupIF, public MqServerCleanupIF, public MqEventIF, public MqServiceIF {
27 public:
28 // Factory Constructor
29 Filter4(MK_TYP const typ=NULL, MqContextC* tmpl=NULL) : MqContextC(typ, tmpl) {
31 }
32
33 private:
34 queue<MqDumpC*> itms;
35 FILE *FH = NULL;
37
38 void ErrorWrite () {
39 auto err = ErrorFORMAT();
40 fprintf(FH, "ERROR: %s\n", err->GetText());
41 fflush(FH);
42 err->Reset ();
43 }
44
45 void Event () {
46 // check if data is available
47 if (itms.empty()) {
48 // no data available, set error-code to CONTINUE
50 } else {
51 // extract the first (oldest) item from the store
52 MqDumpC *dump = itms.front();
53 // an item is available, try to send the data
54 try {
55 // get the filter-context
57 // send BDY data to the link-target
58 try {
59 ProxyForward(ftr, dump);
60 } catch (const MkExceptionC& ex) {
61 if (++errCnt <= 3) {
62 return;
63 } else {
64 throw;
65 }
66 } catch (...) {
67 throw;
68 }
69 } catch (const exception& e) {
70 ErrorCatch (e);
71 // on error write the error-text and "forget" the data
72 ErrorWrite ();
73 }
74 // delete the data, will contine with next item
75 delete dump;
76 itms.pop();
77 errCnt = 0;
78 }
79 }
80
81 void Service (MqContextC * ctx) {
82 auto dump = MqDumpC::Export(ctx);
83 itms.push (dump);
84 SendRETURN();
85 }
86
87 void LOGF () {
88 // get the "link-target"
90 // check "Ident" from the "link-target"
91 if (strcmp(ftr->ConfigGetPrefix(),"Filter4-1") == 0) {
92 // if "Ident" is "transFilter" send the data to the "link-target"
93 ProxyForward(ftr);
94 } else {
95 // if "Ident" is not "transFilter" use the data as file-name to open a file
96 FH = fopen (ReadSTR(), "a");
97 }
98 SendRETURN();
99 }
100
101 // [SlaveGetMaster_example]
102 void WRIT () {
103 Filter4 *ctx = static_cast<Filter4*>(SlaveGetMaster());
104 fprintf (ctx->FH, "%s\n", ReadSTR());
105 fflush (ctx->FH);
106 SendRETURN();
107 }
108 // [SlaveGetMaster_example]
109
110 void EXIT () {
111 ErrorFORMAT()->SetEXIT();
112 }
113
115 while (!itms.empty()) {
116 delete itms.front();
117 itms.pop();
118 }
119 if (FH != NULL) fclose (FH);
120 }
121
122 void ServerSetup() {
123 MqContextC *ftr = static_cast<MqContextC*>(SlaveGetFilter());
124 // SERVER: listen on every token (+ALL)
127 ServiceCreate ("+ALL", this);
129 FH = NULL;
130 }
131};
132
133/*****************************************************************************/
134/* */
135/* M A I N */
136/* */
137/*****************************************************************************/
138
139// [initial_example]
140int MK_CDECL main (int argc, MK_STRN argv[])
141{
144
145 Filter4 filter;
146 try {
147 filter.Init();
148 filter.LinkCreate (MkBufferListC {argc, argv});
150 } catch (const exception& e) {
151 filter.ErrorCatch(e);
152 }
153 return filter.Exit();
154}
155// [initial_example]
156
int main(int argc, MK_STRN argv[])
Definition Filter4.cc:140
tag: nhi1-release-250425
void ServerSetup()
Definition Filter4.cc:122
void ServerCleanup()
Definition Filter4.cc:114
void LOGF()
Definition Filter4.cc:87
void Event()
Definition Filter4.cc:45
void Service(MqContextC *ctx)
Definition Filter4.cc:81
Filter4(MK_TYP const typ=NULL, MqContextC *tmpl=NULL)
Definition Filter4.cc:29
FILE * FH
Definition Filter4.cc:35
queue< MqDumpC * > itms
Definition Filter4.cc:34
MK_I32 errCnt
Definition Filter4.cc:36
void EXIT()
Definition Filter4.cc:110
void ErrorWrite()
Definition Filter4.cc:38
void WRIT()
Definition Filter4.cc:102
PUBLIC data structure for the ccmqmsgque-specific-data → C-API: libmqmsgque::MqContextS
MqDumpC - the class known as dmp or dump is used to export a ccmqmsgque data package as binary … ...
Definition MqDumpC_cc.hh:24
implements the ccmqmsgque API object: ConfigSetEvent
template wrapper for libmqmsgque::MqFactoryS
implements the ccmqmsgque API object: ConfigSetServerCleanup
implements the ccmqmsgque API object: ConfigSetServerSetup
Callback for a Service.
void SetEXIT(MK_STRN callfunc=__builtin_FUNCTION())
#define MK_CDECL
signed int MK_I32
const MK_STRB * MK_STRN
MkErrorC * ErrorCatch(std::exception *exception=NULL, MK_STRN callfunc=__builtin_FUNCTION()) const
void Init(MK_STRN caller=__builtin_FUNCTION())
MK_STRN ConfigGetPrefix() const
C++: MK_STRN ctx.ConfigGetPrefix() → C-API get the libmqmsgque::MqConfigS::dispPrefix
void ConfigSetIgnoreExit(MK_BOOL data)
C++: ctx.ConfigSetIgnoreExit(MK_BOOL data) → C-API set the libmqmsgque::MqSetupS::ignoreExit va...
MkErrorC * ErrorFORMAT() const
C++: MkErrorC* fmtobj.ErrorFORMAT() → C-API helper used to access MkErrorDEFAULT from MqContext...
void ProcessEvent(MqWaitOnEventE wait=MQ_WAIT_NO, MK_TIME_T timeout=MK_TIMEOUT_DEFAULT)
C++: ctx.ProcessEvent(MqWaitOnEventE wait = MQ_WAIT_NO, MK_TIME_T timeout = MK_TIMEOUT_DEFAULT) → C...
MK_I32 Exit(MK_STRN callfunc=__builtin_FUNCTION(), MK_STRN callfile=__builtin_FILE(), MK_I32 callline=__builtin_LINE())
C++: MK_I32 ctx.Exit(MK_STRN callfunc = __builtin_FUNCTION(), MK_STRN callfile = __builtin_FILE(),...
void ProxyForward(MqContextC *targetCtx, MqDumpC *dump=NULL, MK_TIME_T timeout=MK_TIMEOUT_DEFAULT)
C++: sourceCtx.ProxyForward(MqContextC* targetCtx, MqDumpC* dump = NULL, MK_TIME_T timeout = MK_TIME...
MK_STRN ReadSTR()
C++: doc_mq_cc_ReadSTR → C-API read a PRIMITIVE TYPE from the read-data-package …
void SendRETURN()
C++: ctx.SendRETURN() → C-API MqContextC - finish the send-data-block on the server and optiona...
void ServiceCreate(MQ_TOK token, MqServiceCCB callback)
C++: ctx.ServiceCreate(MQ_TOK token, MqServiceICB MqServiceCCB MqServiceIF* cal...
MqContextC * SlaveGetFilter()
C++: MqContextC* ctx.SlaveGetFilter() → C-API get the filter-ctx or the master-ctx …
MqContextC * SlaveGetMaster()
C++: MqContextC* ctx.SlaveGetMaster() → C-API opposite function of MqSlaveGetFilter
static MqDumpC * Export(MqContextC *ctx, MqDumpC *dumpP_inout=NULL)
C++: [constructor,static] MqDumpC* MqDumpC::Export(MqContextC* ctx, MqDumpC* dumpP_inout = NULL) → C...
MqFactoryC * Initial()
C++: MqFactoryC* fct.Initial() → C-API set the initial-attribut to fct …
@ MQ_WAIT_FOREVER
Wait maximum timeout seconds for an event or raise an timeout-error …
static void CcMqSetup()
C++: [static] MqMsgque::Setup() → C-API setup ccmqmsgque internal memory …
namespace for the CcMqMsgque "C++"-API