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