theLink 10.0
Loading...
Searching...
No Matches
MqFactoryC.cs
Go to the documentation of this file.
1
9/* LABEL-INIT */
10
11#define META_STATIC_OVERWRITE
12
13using csmkkernel;
14
15/* LABEL-START */
16
17using System;
18using System.Reflection;
19using System.Runtime.InteropServices;
20using System.Runtime.CompilerServices;
21using System.Collections.Generic;
22using System.Threading;
23
24namespace csmqmsgque {
25
29#if META_IS_OBJECT
30 public partial class MqFactoryC
31#else
32 public partial class MqFactoryC : MkObjectC
33#endif
34 {
35 private readonly static ConstructorInfo ctor = getCtor(typeof(MqFactoryC));
36 private readonly static ThreadLocal<MqFactoryC> MK_NULL = new ThreadLocal<MqFactoryC>(() => {
37 return (MqFactoryC) atomSelfNull(ctor);
38 });
39
40 public static MqFactoryC MqFactoryC_ObjNew (IntPtr hdl) {
41 return hdl != IntPtr.Zero ? (MqFactoryC) atomObjNew(typeof(MqFactoryC), ctor, hdl) : MK_NULL.Value;
42 }
43
44 private static MqFactoryC MqFactoryC_ObjCreate (IntPtr hdl) {
45 return hdl != IntPtr.Zero ? (MqFactoryC) atomObjCreate(typeof(MqFactoryC), ctor, hdl) : MK_NULL.Value;
46 }
47
48 private static IntPtr MqFactoryC_SelfCreate (IntPtr mkrt, IntPtr obj, IntPtr env) {
49 return atomSelfCreate(ctor, obj, env);
50 }
51
52 private static void MqFactoryC_SelfUnlink (IntPtr mkrt, IntPtr self, IntPtr env) {
53 atomSelfUnlink(self, env);
54 }
55
56 internal static void SetupThreadFCT (IntPtr mkrt) {
57 Mq.MqCsTypeUpdate(mkrt, MqCsTypeLookupE.FCT, MqFactoryC_SelfCreate, MqFactoryC_SelfUnlink);
58 }
59
60 #if !META_STATIC_OVERWRITE
61
62 static MqFactoryC() {
63 // M0("MqFactoryC");
64 MqMsgque.Setup();
65 SetupThreadFCT(IntPtr.Zero);
66 }
67
68 #endif
69/* LABEL-END */
70
71 static MqFactoryC() {
72 // init libmqmsgque
73 MqMsgque.Setup();
74 Mq.MqCsTypeUpdate(IntPtr.Zero, MqCsTypeLookupE.FCT, MqFactoryC_SelfCreate, MqFactoryC_SelfUnlink);
75 // init factory
76 if (MqFactoryC.DefaultIdent() == "libmqmsgque") {
77 MqFactoryCT<MqContextC>.Add("csmqmsgque").Default().Initial();
78 }
79 }
80
81 internal MqFactoryC (IntPtr ptr) : base(ptr) {
82 }
83
84 ~MqFactoryC() {
85 Mq.MqFactoryFree(mkrt,hdl);
86 }
87
88 private static MqFactoryCTorF fFactoryCreate = FactoryCreate;
89 private static MqFactoryDTorF fFactoryDelete = FactoryDelete;
90 private static MqFactoryDataFreeF fFactoryDataFree = FactoryDataFree;
91 private static MqFactoryDataCopyF fFactoryDataCopy = FactoryDataCopy;
92
93 // private
94
95 private static MkErrorE FactoryCreate (
96 IntPtr mkrt, IntPtr mqrt, IntPtr tmpl, MqFactoryE create, IntPtr fct, out IntPtr contextP
97 ) {
98 contextP = IntPtr.Zero;
99 try {
100 Object tmplO = MqContextC.MqContextC_ObjNewOrNull(tmpl);
101 ConstructorInfo constr = null;
102
103 if (tmplO != null && (create & (MqFactoryE.CHILD|MqFactoryE.SLAVE|MqFactoryE.FILTER)) > 0) {
104 constr = tmplO.GetType().GetConstructor(new Type[] {typeof(MqContextC)});
105 } else {
106 IntPtr data = Mq.MqFactoryItemGetCreateData(fct);
107 constr = (ConstructorInfo)GCHandle.FromIntPtr(data).Target;
108 }
109 Object[] args = new Object[] {tmplO};
110 contextP = ((MqContextC)(constr).Invoke(args)).hdl;
111
112 } catch (Exception ex) {
114 return MkErrorC.DEFAULT().Catch(ex).Stack();
115 }
116 if ((create & (MqFactoryE.CHILD)) > 0) {
117 Mq.MqSetupDup (mkrt, contextP, tmpl);
118 }
119 return MkErrorE.OK;
120 }
121
122 private static void FactoryDelete (IntPtr mkrt, IntPtr ctx, bool doFactoryCleanup, IntPtr fct) {
123 IntPtr self = Mk.CsGetSelfPtr(ctx);
124 // C# has no "selfDelete" function
125 if (self != IntPtr.Zero) {
126 var selfO = GCHandle.FromIntPtr(self).Target;
127 if (selfO != null) {
128 ((MkObjectC)selfO).Dispose();
129 return;
130 }
131 }
132 // last resort
133 Mq.MqContextDelete(mkrt, ctx);
134 }
135
136 private static void FactoryDataFree (IntPtr mkrt, ref IntPtr data) {
137 GCHandle.FromIntPtr(data).Free();
138 data = IntPtr.Zero;
139 }
140
141 private static void FactoryDataCopy (IntPtr mkrt, ref IntPtr data) {
142 data = (IntPtr)GCHandle.Alloc((ConstructorInfo)GCHandle.FromIntPtr(data).Target);
143 }
144
145 } // END - class "MqFactoryC"
146
147
148 // BEGIN-MqFactoryC - created by 'cs_MqC.tcl -i NHI1_HOME/theLink/c/gen/c_mqmsgque.meta' - DO NOT change
149
150 public partial class MqFactoryC {
151
155
156 // doc-key: MqFactoryC,MqFactoryC-Class-Export,sc_
157
159 new public static MqFactoryC HandleResolve (Int32 netHdl) {
160 IntPtr __retVal__L = Mq.MqFactoryHandleResolve(IntPtr.Zero, netHdl);
161 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
162 }
163
164 // doc-key: MqFactoryC,MqFactoryC-Class-Export,om_
165
166 // skip class-overload: HandleGet = MqFactoryHandleGet → MkObjectHandleGet
167
169 // MqFactoryC_Class_CS_API
170 }
171
172 public partial class MqFactoryC {
173
177
178 // doc-key: MqFactoryC,MqFactoryC-Class-Introspection,oc_
179
181 new public MqFactoryC Next () {
182 IntPtr __retVal__L = Mq.MqFactoryNext(hdl);
183 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
184 }
185
187 new public MqFactoryC Prev () {
188 IntPtr __retVal__L = Mq.MqFactoryPrev(hdl);
189 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
190 }
191
192 // doc-key: MqFactoryC,MqFactoryC-Class-Introspection,sc_
193
195 new public static MqFactoryC Instances () {
196 IntPtr __retVal__L = Mq.MqFactoryInstances(IntPtr.Zero);
197 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
198 }
199
201 // MqFactoryC_Class_CS_API
202 }
203
204 public partial class MqFactoryC {
205
209
210 // doc-key: MqFactoryC,MqFactoryC-Class-Misc,sc_
211
213 new public static MqFactoryC GetNull () {
214 IntPtr __retVal__L = Mq.MqFactoryGetNull();
215 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
216 }
217
219 // MqFactoryC_Class_CS_API
220 }
221
222 public partial class MqFactoryC {
223
227
228 // doc-key: MqFactoryC,MqFactoryC-Get,sc_
229
231 public static MqFactoryC Get (string ident = "") {
232 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
233 IntPtr __retVal__L = Mq.MqFactoryGet(IntPtr.Zero, ident_cstr);
234 Marshal.FreeHGlobal(ident_cstr);
235 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
236 }
237
239 public static MqFactoryC GetCalled (string ident = "") {
240 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
241 IntPtr __retVal__L = Mq.MqFactoryGetCalled(IntPtr.Zero, ident_cstr);
242 Marshal.FreeHGlobal(ident_cstr);
243 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
244 }
245
247 public static MqFactoryC GetCalled (MkBufferListC largs) {
248 IntPtr largs_hdl = MkBufferListC.getOBJ("MkBufferListC",largs);
249 IntPtr __retVal__L = Mq.MqFactoryGetCalledL(IntPtr.Zero, largs_hdl);
250 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
251 }
252
253 // doc-key: MqFactoryC,MqFactoryC-Get,om_
254
256 public string GetOriginalIdent () {
257 IntPtr __retVal__L = Mq.MqFactoryGetOriginalIdent(hdl);
258 return Marshal.PtrToStringAnsi(__retVal__L);
259 }
260
262 // MqFactoryC_Get_CS_API
263 }
264
265 public partial class MqFactoryC {
266
270
271 // doc-key: MqFactoryC,MqFactoryC-Misc,oc_
272
274 public MqFactoryC Default () {
275 IntPtr __retVal__L = Mq.MqFactoryDefault(mkrt, hdl);
276 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
277 }
278
280 public MqFactoryC Initial () {
281 IntPtr __retVal__L = Mq.MqFactoryInitial(mkrt, hdl);
282 return MqFactoryC.MqFactoryC_ObjNew(__retVal__L);
283 }
284
285 // doc-key: MqFactoryC,MqFactoryC-Misc,oco
286
288 public MqContextC New () {
289 IntPtr val_out;
290 MkErrorE errVal = Mq.MqFactoryNew(mkrt, hdl, IntPtr.Zero, out val_out);
291 MkErrorC.Check(hdl, errVal);
292 return MqContextC.MqContextC_ObjNew(val_out);
293 }
294
295 // doc-key: MqFactoryC,MqFactoryC-Misc,om_
296
297 // skip class-overload: Log = MqFactoryLog → MkObjectLog
298
299 // doc-key: MqFactoryC,MqFactoryC-Misc,sm_
300
302 public static string DefaultIdent () {
303 IntPtr __retVal__L = Mq.MqFactoryDefaultIdent(IntPtr.Zero);
304 return Marshal.PtrToStringAnsi(__retVal__L);
305 }
306
308 public static string InitialIdent () {
309 IntPtr __retVal__L = Mq.MqFactoryInitialIdent(IntPtr.Zero);
310 return Marshal.PtrToStringAnsi(__retVal__L);
311 }
312
314 public static void LogAll ([CallerMemberName]string callfunc = null) {
315 IntPtr callfunc_cstr = Marshal.StringToHGlobalAnsi(callfunc);
316 Mq.MqFactoryLogAll(IntPtr.Zero, callfunc_cstr);
317 Marshal.FreeHGlobal(callfunc_cstr);
318 }
319
321 // MqFactoryC_Misc_CS_API
322 }
323
324 public partial class MqFactoryC {
325
329
330 // doc-key: MqFactoryC,MqFactoryC-TOR,oCx
331
333 public MqFactoryC Dup2 (string ident) {
334 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
335 IntPtr __retVal__L = Mq.MqFactoryDup2(mkrt, hdl, ident_cstr);
336 Marshal.FreeHGlobal(ident_cstr);
337 if (__retVal__L == IntPtr.Zero) {
338 throw new MkInitError("MqFactoryC.Dup2");
339 }
340 return MqFactoryC.MqFactoryC_ObjCreate(__retVal__L);
341 }
342
343 // doc-key: MqFactoryC,MqFactoryC-TOR,sCc
344
346 public MqFactoryC(Type constructor, string ident = null) : this(CTOR(constructor, ident)) {}
347
349 public static MqFactoryC Add (Type constructor, string ident = null) {
350 if (ident == null) {ident = constructor.Name;}
351 if (ident == null) {ident = constructor.Name;}
352 IntPtr constructor_c;
353 // this require an Class-Constructor with Signature 'CLASS(MqContextC)' and will be implemented as
354 // 'CLASS(MqContextC tmpl=null) : base(tmpl) {...}' to support the Default-Constructor as well.
355 ConstructorInfo constr = constructor.GetConstructor(new Type[] {typeof(MqContextC)});
356 if (constr == null) {
357 throw new System.Exception("unable to get Factory constructor");
358 } else {
359 constructor_c = (IntPtr) GCHandle.Alloc(constr);
360 }
361 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
362 IntPtr __retVal__L = Mq.MqFactoryAdd(IntPtr.Zero, IntPtr.Zero, fFactoryCreate, constructor_c, fFactoryDataFree, fFactoryDataCopy, fFactoryDelete, IntPtr.Zero, null, null, ident_cstr);
363 Marshal.FreeHGlobal(ident_cstr);
364 if (__retVal__L == IntPtr.Zero) {
365 throw new MkInitError("MqFactoryC.Add");
366 }
367 return MqFactoryC.MqFactoryC_ObjCreate(__retVal__L);
368 }
369
371 protected static IntPtr CTOR (Type constructor, string ident = null) {
372 if (ident == null) {ident = constructor.Name;}
373 IntPtr constructor_c;
374 // this require an Class-Constructor with Signature 'CLASS(MqContextC)' and will be implemented as
375 // 'CLASS(MqContextC tmpl=null) : base(tmpl) {...}' to support the Default-Constructor as well.
376 ConstructorInfo constr = constructor.GetConstructor(new Type[] {typeof(MqContextC)});
377 if (constr == null) {
378 throw new System.Exception("unable to get Factory constructor");
379 } else {
380 constructor_c = (IntPtr) GCHandle.Alloc(constr);
381 }
382 IntPtr ident_cstr = Marshal.StringToHGlobalAnsi(ident);
383 IntPtr __retVal__L = Mq.MqFactoryAdd(IntPtr.Zero, IntPtr.Zero, fFactoryCreate, constructor_c, fFactoryDataFree, fFactoryDataCopy, fFactoryDelete, IntPtr.Zero, null, null, ident_cstr);
384 Marshal.FreeHGlobal(ident_cstr);
385 if (__retVal__L == IntPtr.Zero) {
386 throw new MkInitError("MqFactoryC.CTOR");
387 }
388 return (IntPtr)__retVal__L;
389 }
390
392 // MqFactoryC_TOR_CS_API
393 }
394
395 // END-MqFactoryC - created by 'cs_MqC.tcl -i NHI1_HOME/theLink/c/gen/c_mqmsgque.meta' - DO NOT change
396
397 //
398 // ##############################################################################################
399 //
400
403 public class MqFactoryCT<T> : MqFactoryC
404 where T : MqContextC
405 {
406 private readonly static ConstructorInfo ctor = getCtor(typeof(MqFactoryCT<T>));
407
408 internal MqFactoryCT(IntPtr ptr) : base(ptr) {
409//printTyp(ptr,"MqFactoryT");
410 }
411
412 private static MqFactoryCT<T> MqFactoryCT_ObjNew (IntPtr hdl) {
413 return (MqFactoryCT<T>) atomObjNew(typeof(MqFactoryCT<T>), ctor, hdl);
414 }
415
417 public static MqFactoryCT<T> Add(string ident = null) {
418#if META_STRONG_REF
419 return MqFactoryCT<T>.MqFactoryCT_ObjNew(CTOR(typeof(T),ident));
420#else
421 var fct = CTOR(typeof(T),ident);
422 var ret = MqFactoryCT<T>.MqFactoryCT_ObjNew(fct);
423 Mk.CsMakePersistent(fct);
424 return ret;
425#endif
426 }
427
428 public new T New() {
429 return (T) base.New();
430 }
431
432 public new MqFactoryCT<T> Initial() {
433 return (MqFactoryCT<T>) base.Initial();
434 }
435
436 }
437
438 //
439 // ##############################################################################################
440 //
441
444 internal class MqFactoryCException : Exception
445 {
446 internal MqFactoryCException(string message = "") : base("MqFactoryC exception: " + message) {}
447 }
448
449} // END - namespace "csmqmsgque"
csmqmsgque.MqMsgque Mq
static void Check(IntPtr ctx, MkErrorE err)
static object atomObjNew(Type type, ConstructorInfo ctor, IntPtr obj)
static object atomObjCreate(Type type, ConstructorInfo ctor, IntPtr obj)
static void atomSelfUnlink(IntPtr self, IntPtr env)
static object atomSelfNull(ConstructorInfo ctor)
static ConstructorInfo getCtor(Type type)
static IntPtr atomSelfCreate(ConstructorInfo ctor, IntPtr obj, IntPtr env)
static unsafe void CsMakePersistent(IntPtr hdl)
static unsafe IntPtr CsGetSelfPtr(IntPtr hdl)
MqContextC - the class known as ctx or context is the application-handle of the application-server an...
Definition MqHigh.cs:22
static MqContextC MqContextC_ObjNew(IntPtr hdl)
Definition MqContextC.cs:42
Implements the factory-template.
static MqFactoryCT< T > Add(string ident=null)
C#: [constructor,static] MqFactoryC MqFactoryC.Add(Type constructor, string ident = null) → C-API ...
new MqFactoryCT< T > Initial()
MqFactoryC - the class known as fct or factory is used to provide an interface to create one or more ...
static MqFactoryC MqFactoryC_ObjNew(IntPtr hdl)
Definition MqFactoryC.cs:40
MkErrorE Stack([CallerMemberName]string callfunc=null,[CallerFilePath]string callfile=null,[CallerLineNumber]int callline=-1)
MkErrorC Catch(Exception exception=null,[CallerMemberName]string callfunc=null)
static MkErrorC DEFAULT()
#define MK_NULL
MkErrorE
enum MkErrorE(* MqFactoryCTorF)(MK_RT mkrt, MQ_RT mqrt, MQ_CTX const tmpl, enum MqFactoryE create, MQ_FCT const fct, MQ_CTX *ctx_out)
type of a MqFactoryC constructor
void(* MqFactoryDataFreeF)(MK_RT mkrt, MK_PTR *dataP)
prototype for a free additional factory data function
void(* MqFactoryDTorF)(MK_RT mkrt, MQ_CTX ctx, bool doFactoryCleanup, MQ_FCT const fct)
type of a MqFactoryC destructor
void(* MqFactoryDataCopyF)(MK_RT mkrt, MK_PTR *dataP)
prototype for a copy additional factory data function
new MqFactoryC Prev()
C#: MqFactoryC fct.Prev() → C-API get previous instance from linked-list of MqFactoryS type
new static MqFactoryC Instances()
C#: [static] MqFactoryC MqFactoryC.Instances() → C-API get head-instance from linked-list of MqF...
new MqFactoryC Next()
C#: MqFactoryC fct.Next() → C-API get next instance from linked-list of MqFactoryS type
new static MqFactoryC GetNull()
C#: [static] MqFactoryC MqFactoryC.GetNull() → C-API Null-Slot - return a MqFactoryC typed NULL ...
new static MqFactoryC HandleResolve(Int32 netHdl)
C#: [static] MqFactoryC MqFactoryC.HandleResolve(Int32 netHdl) → C-API Handle-Resolve-Slot - ret...
#define MqFactoryCT
class as MkTypeDefS-class-type for MqFactoryC in the Target-Programming-Language (TPL) …
static MqFactoryC GetCalled(string ident="")
C#: [static] MqFactoryC MqFactoryC.GetCalled(string ident = "") → C-API returns the MqFactoryC i...
static MqFactoryC GetCalled(MkBufferListC largs)
C#: [static] MqFactoryC MqFactoryC.GetCalled(MkBufferListC largs) → C-API returns the MqFactoryC...
static MqFactoryC Get(string ident="")
C#: [static] MqFactoryC MqFactoryC.Get(string ident = "") → C-API return the MqFactoryC
string GetOriginalIdent()
C#: string fct.GetOriginalIdent() → C-API helper function to return MqFactoryS....
static void LogAll([CallerMemberName]string callfunc=null)
C#: [static] MqFactoryC.LogAll([CallerMemberName]string callfunc = null) → C-API log all "factor...
MqFactoryC Default()
C#: MqFactoryC fct.Default() → C-API set the default-attribute to the factory …
MqFactoryC Initial()
C#: MqFactoryC fct.Initial() → C-API set the initial-attribut to fct …
MqContextC New()
C#: MqContextC fct.New() → C-API create a new MqContextC from a MqFactoryC …
static string DefaultIdent()
C#: [static] string MqFactoryC.DefaultIdent() → C-API return the factory-identifier of the defau...
static string InitialIdent()
C#: [static] string MqFactoryC.InitialIdent() → C-API return the factory-identifier of the initi...
MqFactoryC(Type constructor, string ident=null)
CONSTRUCTOR.
static MqFactoryC Add(Type constructor, string ident=null)
C#: [constructor,static] MqFactoryC MqFactoryC.Add(Type constructor, string ident = null) → C-API ...
MqFactoryC Dup2(string ident)
C#: [constructor] MqFactoryC fct.Dup2(string ident) → C-API create a duplicate of the singleton ...
static IntPtr CTOR(Type constructor, string ident=null)
C#: [constructor,static] MqFactoryC MqFactoryC.Add(Type constructor, string ident = null) → C-API ...
MqFactoryE
the factory is called to create an object for ...