HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
server.c
Go to the documentation of this file.
1 #include <unistd.h>
2 
3 #include <errno.h>
4 #include <stdio.h>
5 
6 #include <hipc/scfg.h>
7 #include <hipc/posix/usoc.h>
8 #include <hipc/usoc.h>
9 #include <hipc/usocutils.h>
10 
11 #include "CFGled.h"
12 #include "CFGled_scfg.h"
13 
14 static struct STRUprm prm;
15 
16 void hipcsvsLedUpdate(struct STRUprm *prm_p)
17 {
18  fprintf(stderr, "led:%d\n", prm_p->led);
19 
20  return;
21 }
22 
23 enum HIPC_errno hipcsvsLedRun(struct HIPC_usoc *const so_p)
24 {
25  hipc_msgd mdR;
26  hipc_msgd mdS;
27  enum HIPC_errno retval;
28 
29  for (;;) {
30  retval =
32  if (HIPC_SUCCESS != retval) {
33  return retval;
34  }
35 
36  switch (hipcMsgdType(&mdR)) {
38  return HIPC_SUCCESS;
40  retval = hipcGenmdSuccessToGet(&mdS, &mdR, &prm, sizeof(prm));
41  if (HIPC_SUCCESS != retval) {
42  return retval;
43  }
44  break;
46  retval = hipcMsgdSetBdyForPut(&mdR, &prm, sizeof(prm));
47  if (HIPC_SUCCESS != retval) {
48  return retval;
49  }
50  retval = hipcUsocRead(so_p, hipcMsgdBdyPtr(&mdR),
51  hipcMsgdBdySize(&mdR));
52  if (HIPC_SUCCESS != retval) {
53  return retval;
54  }
55  hipcGenmdSuccess(&mdS);
57  break;
58  default:
60  }
61  retval = hipcUsocWriteMsgd(so_p, &mdS);
62  if (HIPC_SUCCESS != retval) {
63  return retval;
64  }
65  }
66 }
67 
68 void hipcMain(struct HIPC_usoc *const so_p)
69 {
70  hipc_msgd mdQ;
71  enum HIPC_errno retval;
72 
73  retval = hipcUsocAcceptSimple(so_p, &HIPCUD_CFGled_SCFG);
74  if (HIPC_SUCCESS == retval) {
75  retval = hipcsvsLedRun(so_p);
76  }
77 
78  hipcGenmdQuit(&mdQ, retval, NULL);
79 
80  if ((HIPC_ERR_S_IO_READ != retval) && (HIPC_ERR_S_IO_WRITE != retval)) {
81  hipcUsocWriteMsgd(so_p, &mdQ);
82  }
83 
84  return;
85 }
86 
87 int main(void)
88 {
89  struct HIPC_usoc usoc;
90 
91  prm.led = 0;
92  hipcPosixUsocInit(&usoc, STDIN_FILENO, STDOUT_FILENO);
93  hipcMain(&usoc);
94 
95  fprintf(stderr, "end\n");
96 
97  return 0;
98 }
enum HIPC_errno hipcUsocAcceptSimple(struct HIPC_usoc *const so_p, const struct HIPC_scfg *const cfg_p)
Accepts a HIPC session of cfg_p.
Definition: usocutils.c:141
enum HIPC_errno hipcUsocRead(struct HIPC_usoc *so_p, void *buf, const size_t size)
Reads exactly size bytes from so_p.
Definition: posix_usoc.c:24
enum HIPC_errno hipcGenmdSuccessToGet(hipc_msgd *const mds_p, hipc_msgd const *const mdr_p, void *const stru_p, const size_t stru_size)
Initializes mds_p as a response to mdr_p whose type must be GET.
Definition: msgd.c:102
void hipcPosixUsocInit(struct HIPC_usoc *so_p, const int fdr, const int fdw)
Initializes a universal socket.
Definition: posix_usoc.c:14
enum HIPC_errno hipcsvsLedRun(struct HIPC_usoc *const so_p)
Definition: server.c:23
enum HIPC_errno hipcUsocWriteMsgd(struct HIPC_usoc *const so_p, hipc_msgd const *const md_p)
Writes md_p to so_p.
Definition: usocutils.c:14
HIPC_errno
Definition: hipc.h:4
enum HIPC_errno hipcMsgdSetBdyForPut(hipc_msgd *const mdr_p, void *const stru_p, const size_t stru_size)
Sets a body to a HIPC message data that contains a header of a PUT message.
Definition: msgd.c:140
unsigned char hipcMsgdBdySize(hipc_msgd const *const md_p)
Returns body size of a HIPC message data.
Definition: msgd.c:9
#define hipcGenmdQuit(md_p, hipc_errno, errdtlstr)
Initializes a HIPC message data as a QUIT message.
Definition: msgd.h:26
#define hipcGenmdSuccess(md_p)
Initializes a HIPC message data as a SUCCESS message.
Definition: msgd.h:35
static struct STRUprm prm
Definition: server.c:14
Definition: usoc.h:4
int main(void)
Definition: server.c:87
#define hipcMsgdBdyPtr(md_p)
Returns a pointer to a body of a HIPC message data.
Definition: msgd.h:52
unsigned char hipcMsgdType(hipc_msgd const *const md_p)
Returns type of a HIPC message data.
Definition: msgd.c:20
void hipcMain(struct HIPC_usoc *const so_p)
Definition: server.c:68
#define hipcMsgdHdrPtr(md_p)
Returns a pointer to a header of a HIPC message data.
Definition: msgd.h:44
void hipcsvsLedUpdate(struct STRUprm *prm_p)
Definition: server.c:16