HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
client_rt.c
Go to the documentation of this file.
1 #include <unistd.h>
2 
3 #include <assert.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 
8 #include <hipc/session.h>
9 
10 #include "CFGrt.h"
11 #include "CFGrt_ccfg.h"
12 
13 enum HIPC_errno handler_log(struct HIPC_client *cl_p, const hipc_msg msg,
14  void *cimg, void *arg)
15 {
16  struct STRUlog *log_p;
17  FILE *fp;
18 
19  assert(NULL != cimg);
20  assert(NULL != arg);
21  log_p = cimg;
22  fp = arg;
23 
24  fprintf(fp, "tick/out %5d/%d\n", log_p->tick, log_p->output);
25 
26  return HIPC_SUCCESS;
27 }
28 
29 int main(void)
30 {
31  struct STRUprm data[] = {
32  {4, {1, 1, 1, 0}},
33  {3, {1, 1, 0}},
34  {2, {1, 0}},
35  {0},
36  };
37  struct STRUlog log;
38  FILE *fp;
39  hipc_session sess;
40  int fdr = STDIN_FILENO;
41  int fdw = STDOUT_FILENO;
42  int i;
43 
44  fp = fopen("log.txt", "w");
45  if (NULL == fp) {
46  perror("log.txt");
47  exit(EXIT_FAILURE);
48  }
49 
50  hipcOpen(&sess, &HIPCUD_CFGrt_CCFG,
51  hipcPosixReadMsg, &fdr, hipcPosixWriteMsg, &fdw);
52  HIPC_ERRCHECK(&sess);
53 
54  hipcSetHandler(&sess, "STRUlog", &log, handler_log, fp);
55  HIPC_ERRCHECK(&sess);
56 
57  for (i = 0; i < sizeof(data) / sizeof(data[0]); ++i) {
58  hipcPut(&sess, "STRUprm", &data[i]);
59  HIPC_ERRCHECK(&sess);
60  }
61 
62  hipcClose(&sess);
63  HIPC_ERRCHECK(&sess);
64 
65  fclose(fp);
66 
67  fprintf(stderr, "end\n");
68 
69  return 0;
70 }
unsigned char hipc_msg[HIPC_MSG_ALLOCSIZE]
Definition: msg.h:8
int main(void)
Definition: client_rt.c:11
enum HIPC_errno hipcPut(hipc_session *const sess_p, char const *const str, void *const cimg)
Puts data specified by str from a HIPC server.
Definition: session.c:361
enum HIPC_errno hipcOpen(hipc_session *const sess_p, struct HIPC_client const *const clbase_p, enum HIPC_errno(*rfnc_p)(void *, hipc_msg), void *rarg, enum HIPC_errno(*wfnc_p)(void *, const hipc_msg), void *warg)
Open a session to a HIPC server.
Definition: session.c:217
HIPC_errno
Definition: hipc.h:4
enum HIPC_errno handler_log(struct HIPC_client *cl_p, const hipc_msg msg, void *cimg, void *arg)
Definition: client_rt.c:13
enum HIPC_errno hipcPosixReadMsg(void *arg, hipc_msg msg)
Read a HIPC message from fd.
enum HIPC_errno hipcClose(hipc_session *const sess_p)
Closes a session.
Definition: session.c:276
enum HIPC_errno hipcSetHandler(hipc_session *const sess_p, char const *const str, void *const cimg, enum HIPC_errno(*hndlr_p)(struct HIPC_client *, const hipc_msg, void *, void *), void *const arg)
Set a handler to a structure type.
Definition: session.c:174
enum HIPC_errno hipcPosixWriteMsg(void *arg, const hipc_msg msg)
Write a HIPC message to fd.
#define HIPC_ERRCHECK(sess_p)
Checks whether an error has occurred.
Definition: session.h:72