Belle II Software development
nsmlib2.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* ---------------------------------------------------------------------- *\
10 nsmlib2.h
11
12 revision history can be found in nsmlib2.c
13\* ---------------------------------------------------------------------- */
14
15#ifndef __nsmlib2_h__
16#define __nsmlib2_h__
17
18/* -- INCLUDE FILES -------------------------------------------------- */
19#include <stdio.h> /* for FILE * */
20#include <netinet/in.h> /* for struct sockaddr_in */
21
22#include "nsm2/nsm2.h"
23
24#if defined(__cplusplus)
25extern "C" {
26#endif
27
28/* -- DATA TYPES ----------------------------------------------------- */
29#ifndef __nsm2_typedef_context__
30#define __nsm2_typedef_context__
32typedef struct NSMcontext_struct NSMcontext;
33#endif /* nsm2_typedef_context */
34
35#ifndef __nsm2_typedef_parse__
36#define __nsm2_typedef_parse__
37struct NSMparse_struct;
38typedef struct NSMparse_struct NSMparse;
39#endif /* nsm2_typedef_parse */
40
41#define NSMSYS_NAME_SIZ 31
42
43#define NSMLIB_MAX_RETRY 30
44#define NSMLIB_WAIT_RETRY 2
45#define NSMLIB_MAX_CALLBACK 1024
46
47typedef int (*NSMhook_t)(NSMmsg* msg, NSMcontext* nsmc);
48
49typedef enum NSMfunctype_enum {
50 NSMLIB_FNNON, /* no entry */
51 NSMLIB_FNSYS, /* for NSMfunc_t (NSM2 standard) with NSMmsg/from */
52 NSMLIB_FNSTD, /* for NSMfunc_t (NSM2 standard) with NSMmsg/from */
53 NSMLIB_FNREQ, /* for NSMfuncr_t with req/seq/pars/from */
54 NSMLIB_FNDAT, /* for NSMfuncd_t with req/seq/pars/from/len/msg */
55 NSMLIB_FNMSG, /* for NSMfuncm_t with req/seq/msg/from */
56 NSMLIB_FNERR, /* for NSMfunce_t with req/seq/msg/from/node */
57} NSMfunctype;
58
59typedef struct {
60 int req;
61 NSMfunctype functype;
62 NSMfunc_t callback;
63 char name[64];
65
67struct NSMrecvqueue_struct;
68struct NSMmem_struct;
69struct NSMsys_struct;
70
72 /* seq */
73 int seq;
74
75 /* error code (when can't be returned) */
76 int errc;
77 char errs[1024]; /* error string in case of NSMEUNEXPECTED */
78 int errn; /* errno in case of system error */
79
80 /* initnet (network related) */
81 int initnet_done;
82 int sock;
83 int port;
84 int shmkey;
85 struct sockaddr_in sa;
86 char nodename[NSMSYS_NAME_SIZ + 1];
87 char hostname[1024];
88
89 /* initshm (shared memory related) */
90 int initshm_done;
91 int sysid;
92 struct NSMsys_struct* sysp;
93 int memid;
94 struct NSMmem_struct* memp;
95
96 /* initsig (signal handler related) */
97 int usesig;
98 int initsig_done;
99 int pipe_rd;
100 int pipe_wr;
101 int reqwait;
102 int nreq;
103 NSMrequest req[NSMLIB_MAX_CALLBACK];
104
105 /* initcli (client related) */
106 int nodeid;
107 struct NSMcontext_struct* next;
108
109 /* recv queue */
110 struct NSMrecvqueue_struct* recvqueue;
111
112 /* callback hook */
113 NSMhook_t hook;
114 const void* hookptr;
115
116 /* more pointer to be used by a wrapper */
117 const void* wrapptr;
118};
119
120
121void nsmlib_logflush();
122FILE* nsmlib_logging(FILE* logfp);
123void nsmlib_checkpoint(NSMcontext* nsmc, int val);
124int nsmlib_debuglevel(int val);
125int nsmlib_addincpath(const char* path);
126const char* nsmlib_nodename(NSMcontext* nsmc, int nodeid);
127int nsmlib_nodeid(NSMcontext* nsmc, const char* nodename);
128int nsmlib_nodepid(NSMcontext* nsmc, const char* nodename);
129int nsmlib_nodeproc(NSMcontext* nsmc, const char* nodename);
130int nsmlib_recv(NSMcontext* nsmc, struct NSMtcphead_struct* hp, int wait_msec);
131int nsmlib_reqid(NSMcontext* nsmc, const char* reqname);
132const char* nsmlib_reqname(NSMcontext* nsmc, int reqid);
133const char* nsmlib_strerror(NSMcontext* nsmc);
134int nsmlib_callback(NSMcontext* nsmc, const char* name,
135 NSMcallback_t callback, NSMfunctype functype);
136int nsmlib_readmem(NSMcontext* nsmc, void* buf,
137 const char* dat, const char* fmt, int rev);
138int nsmlib_statmem(NSMcontext* nsmc,
139 const char* dat, char* fmtbuf, int bufsiz);
140void* nsmlib_openmem(NSMcontext* nsmc,
141 const char* dat, const char* fmt, int rev);
142void* nsmlib_allocmem(NSMcontext* nsmc,
143 const char* dat, const char* fmt, int rev, float cycle);
144int nsmlib_flushmem(NSMcontext* nsmc,
145 const void* ptr, int siz);
146int nsmlib_sendreq(NSMcontext* nsmc,
147 const char* node, const char* req,
148 uint npar, int* pars, int len, const char* datap);
149int nsmlib_register_request(NSMcontext* nsmc, const char* name);
150NSMcontext* nsmlib_init(const char* nodename, const char* host,
151 int port, int shmkey);
152int nsmlib_term(NSMcontext* nsmc);
153void nsmlib_usesig(NSMcontext* nsmc, int usesig);
154NSMcontext* nsmlib_selectc(int usesig, unsigned int msec);
155void nsmlib_call(NSMcontext* nsmc, struct NSMtcphead_struct* hp);
156NSMparse* nsmlib_parsefile(const char* datname, int revision,
157 const char* incpath, char* fmtstr, int* revisionp);
158
159#if defined(__cplusplus)
160}
161#endif
162
163#endif /* __nsmlib2_h__ */
164
165/* -- (emacs outline mode setup) ------------------------------------- */
166/*
167// Local Variables: ***
168// mode:outline-minor ***
169// outline-regexp:"^/\\* --[+ ]" ***
170// End: ***
171*/
Definition: nsm2.h:224