theLink 10.0
Loading...
Searching...
No Matches
Filter6.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 &context
17
18#include <stdexcept>
19#include <stdlib.h>
20#include <stdio.h>
21#include <regex>
22#include <fstream>
23
24using namespace std;
25using namespace ccmqmsgque;
26
27class Filter6 : public MqContextC, public MqServerSetupIF, public MqServerCleanupIF, public MqEventIF {
28 friend class MqFactoryCT<Filter6>;
29
30 private:
32
33 private:
34 Filter6(MK_TYP const typ, MqContextC* tmpl=NULL) : MqContextC(typ, tmpl) {
36 rgx = "^(?:Filter6-1|Filter6|fs1.*)$";
37 }
38
39 private:
40 std::ofstream outfile;
41 regex rgx;
42
43 void ErrorWrite () {
44 auto err = ErrorFORMAT();
45 if (outfile.is_open()) {
46 outfile << "ERROR: " << err->GetText() << endl;
47 outfile.flush();
48 } else {
49 err->Println();
50 }
51 err->Reset();
52 }
53
54 void LOGF () {
55 // get the "link-target"
57 // check "Ident" from the "link-target"
58 if (std::regex_match(ftr->ConfigGetName(),rgx)) {
59 // if "Ident" is not "transFilter" use the data as file-name to open a file
60 outfile.open(ReadSTR(), std::ios_base::app);
61 } else {
62 // if "Ident" is "transFilter" send the data to the "link-target"
63 ProxyForward(ftr);
64 }
65 SendRETURN();
66 }
67
68 static void WRIT (MqContextC *ctx) {
69 // get the "master"
70 Filter6 *master = dynamic_cast<Filter6*>(ctx->SlaveGetMaster());
71 if (std::regex_match(master->ConfigGetName(),master->rgx)) {
72 master->outfile << ctx->ReadSTR() << endl;
73 master->outfile.flush();
74 } else {
75 ctx->ProxyForward(master);
76 }
77 ctx->SendRETURN();
78 }
79
80 void EXIT () {
81 Exit();
82 }
83
84 void SOEX () {
86 }
87
88 void FilterIn () {
90 SendRETURN();
91 }
92
93 void Event () {
94 // check if data is available
95 if (StorageCount() == 0LL) {
96 // no data available, set error-code to CONTINUE
98 } else {
99 MQ_LTR Id = 0LL;
100 // an item is available, try to send the data
101 try {
102 // get the filter-context
103 MqContextC *ftr = SlaveGetFilter();
104 // read package from storage
105 Id = StorageImport();
106 // forward the entire BDY data to the ftr-target
107 try {
108 ProxyForward(ftr);
109 } catch (const MkExceptionC& e) {
111 StorageDecrRef(Id);
112 return;
113 } else {
114 throw;
115 }
116 } catch (...) {
117 throw;
118 }
119 } catch (const exception& e) {
120 ErrorCatch (e);
121 // on error write the error-text and "forget" the data
122 ErrorWrite();
123 }
124 // on "success" or on "error" delete item from storage
125 if (Id != 0LL) StorageDelete(&Id);
126 }
127 }
128
130 outfile.close();
131 }
132
133 // [filter_service_example]
134 void ServerSetup() {
135 MqContextC *ftr = SlaveGetFilter();
136 // SERVER: listen on every token (+ALL)
141 ServiceStorage ("PRNT");
142 ServiceStorage ("PRN2");
143 ftr->ServiceCreate ("WRIT", MqTokenCCB(&Filter6::WRIT));
145 ftr->ServiceProxy ("WRT2", MQ_SLAVE_MASTER);
146
147 if (isParent()) {
148 LinkCheckOptionI32 ("--retryCnt", &Filter6::retryCnt);
149 }
150 }
151 // [filter_service_example]
152
153 public:
154
155 static void __attribute__ ((noreturn))
157 {
158 fputs("\n", stderr);
159 fprintf(stderr, "usage: %s [OPTION]... [ARGUMENT]...\n", base);
160 fputs("\n", stderr);
161 fputs(" This tool is database (MqStorage...) test tool of NHI1.\n", stderr);
162 fputs("\n", stderr);
163 fprintf(stderr, " %s [ARGUMENT]... syntax:\n", base);
164 fprintf(stderr, " aclient... %c %s ... %c aserver\n", MK_ALFA, base, MK_ALFA);
165 fputs("\n", stderr);
166 fputs(MqHelp (NULL), stderr);
167 fputs("\n", stderr);
168 fprintf(stderr, " %s [OPTION]:\n", base);
169 fputs( " -h, --help print this help\n", stderr);
170 fputs("\n", stderr);
171 fputs( " --retryCnt how often an item should be send on error (default: 3)\n", stderr);
172 fputs("\n", stderr);
173
174 exit(EXIT_SUCCESS);
175 }
176};
177
178int Filter6::retryCnt = 3;
179
180/*****************************************************************************/
181/* */
182/* M A I N */
183/* */
184/*****************************************************************************/
185
186// [error_example]
187int MK_CDECL main (int argc, MK_STRN argv[])
188{
190 // define factory
191 auto Filter6F = MqFactoryCT<Filter6>::Add("Filter6");
192 // modify default type
193 Filter6F->Type()->fHelp = Filter6::Help;
194 // create object from factory
195 Filter6 *filter = Filter6F->New();
196 try {
197 filter->LinkCreate (MkBufferListC {argc, argv});
199 } catch (const exception& e) {
200 filter->ErrorCatch(e);
201 }
202 return filter->Exit();
203}
204// [error_example]
205
int main(int argc, MK_STRN argv[])
Definition Filter6.cc:187
tag: nhi1-release-250425
void Event()
Definition Filter6.cc:93
static void Help(MK_STRN base)
Definition Filter6.cc:156
Filter6(MK_TYP const typ, MqContextC *tmpl=NULL)
Definition Filter6.cc:34
regex rgx
Definition Filter6.cc:41
void FilterIn()
Definition Filter6.cc:88
void EXIT()
Definition Filter6.cc:80
void SOEX()
Definition Filter6.cc:84
static void WRIT(MqContextC *ctx)
Definition Filter6.cc:68
void ServerSetup()
Definition Filter6.cc:134
static MK_I32 retryCnt
Definition Filter6.cc:31
void ErrorWrite()
Definition Filter6.cc:43
void ServerCleanup()
Definition Filter6.cc:129
void LOGF()
Definition Filter6.cc:54
std::ofstream outfile
Definition Filter6.cc:40
PUBLIC data structure for the ccmqmsgque-specific-data → C-API: libmqmsgque::MqContextS
implements the ccmqmsgque API object: ConfigSetEvent
template wrapper for libmqmsgque::MqFactoryS
implements the ccmqmsgque API object: ConfigSetServerCleanup
implements the ccmqmsgque API object: ConfigSetServerSetup
void SetEXIT(MK_STRN callfunc=__builtin_FUNCTION())
#define MK_CDECL
#define MK_ALFA
signed int MK_I32
const MK_STRB * MK_STRN
MkErrorC * ErrorCatch(std::exception *exception=NULL, MK_STRN callfunc=__builtin_FUNCTION()) const
void(*) MqTokenCCB(MqContextC *)
class-callback
MK_STRN ConfigGetName() const
C++: MK_STRN ctx.ConfigGetName() → C-API get the name of the context object
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 ServiceProxy(MQ_TOK token, MQ_SLAVE_ID id=MQ_SLAVE_OTHER)
C++: ctx.ServiceProxy(MQ_TOK token, MQ_SLAVE_ID id = MQ_SLAVE_OTHER) → C-API create a service t...
void ServiceStorage(MQ_TOK token)
C++: ctx.ServiceStorage(MQ_TOK token) → C-API setup a service listen on a MqContextC_ServiceApi...
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
MK_I32 StorageErrCnt(MQ_LTR transLId)
C++: MK_I32 ctx.StorageErrCnt(MQ_LTR transLId) → C-API increment and return the database row-er...
MQ_LTR StorageDelete(MQ_LTR *transLIdP_inout=0)
C++: MQ_LTR ctx.StorageDelete(MQ_LTR *transLIdP_inout = 0) → C-API delete the storage-row ident...
MQ_LTR StorageExport()
C++: MQ_LTR ctx.StorageExport() → C-API export the read-data-package into the STORAGE …
void StorageDecrRef(MQ_LTR transLId)
C++: ctx.StorageDecrRef(MQ_LTR transLId) → C-API decrease the internal refCount lock of the dat...
MQ_LTR StorageCount()
C++: MQ_LTR ctx.StorageCount() → C-API count the number of storage-rows …
MQ_LTR StorageImport(MQ_LTR *transLIdP_inout=0)
C++: MQ_LTR ctx.StorageImport(MQ_LTR *transLIdP_inout = 0) → C-API import the storage-package i...
@ MQ_WAIT_FOREVER
Wait maximum timeout seconds for an event or raise an timeout-error …
@ MQ_SLAVE_MASTER
internal: the master-slave-id, (on a slave get the master)
MK_STR MqHelp(MK_STRN tool)
write ccmqmsgque specific user-help to stderr
static void CcMqSetup()
C++: [static] MqMsgque::Setup() → C-API setup ccmqmsgque internal memory …
int MQ_LTR
32bit longterm transaction token because PHP-32 does NOT support long long
namespace for the CcMqMsgque "C++"-API