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