HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
hipcsvs_led.c
Go to the documentation of this file.
1 #include <string.h>
2 
3 #include <hipc/scfg.h>
4 #include <hipc/usoc.h>
5 #include <hipc/usocutils.h>
6 
7 #include "CFGled.h"
8 #include "CFGled_scfg.h"
9 #include "hipcsvs_led.h"
10 
11 static struct STRUprm prm;
12 
13 void hipcsvsLedInit(void)
14 {
15  prm.led = 0;
17 
18  return;
19 }
20 
21 enum HIPC_errno hipcsvsLedRun(struct HIPC_usoc *const so_p,
22  hipc_msgd * const mdq_p)
23 {
24  hipc_msgd mdR;
25  hipc_msgd mdS;
26  enum HIPC_errno retval;
27 
28  for (;;) {
29  retval =
31  if (HIPC_SUCCESS != retval) {
32  return hipcGenmdQuit(mdq_p, retval, "Header");
33  }
34 
35  switch (hipcMsgdType(&mdR)) {
37  return hipcGenmdQuit(mdq_p, HIPC_SUCCESS, NULL);
39  if (HIPCUD_STRUprm != hipcMsgdStruno(&mdR)) {
41  "GETc0");
42  }
43  retval = hipcGenmdSuccessToGet(&mdS, &mdR, &prm, sizeof(prm));
44  if (HIPC_SUCCESS != retval) {
45  return hipcGenmdQuit(mdq_p, retval, "GETr");
46  }
47  break;
49  if (HIPCUD_STRUprm != hipcMsgdStruno(&mdR)) {
51  "PUTc0");
52  }
53  retval = hipcMsgdSetBdyForPut(&mdR, &prm, sizeof(prm));
54  if (HIPC_SUCCESS != retval) {
55  return hipcGenmdQuit(mdq_p, retval, "PUTs");
56  }
57  retval = hipcUsocRead(so_p, hipcMsgdBdyPtr(&mdR),
58  hipcMsgdBdySize(&mdR));
59  if (HIPC_SUCCESS != retval) {
60  return hipcGenmdQuit(mdq_p, retval, "PUTb");
61  }
62  if (1 < prm.led) {
63  return hipcGenmdQuit(mdq_p, HIPC_ERR_S_INV_UDATA,
64  "1 < prm.led");
65  }
66  hipcGenmdSuccess(&mdS);
68  break;
69  default:
70  return hipcGenmdQuit(mdq_p, HIPC_ERR_S_INV_MSG_TYPE, NULL);
71  }
72  retval = hipcUsocWriteMsgd(so_p, &mdS);
73  if (HIPC_SUCCESS != retval) {
74  return hipcGenmdQuit(mdq_p, retval, "RESP");
75  }
76  }
77 }
78 
79 void hipcMain(struct HIPC_usoc *const so_p)
80 {
81  hipc_msgd mdQ;
82  enum HIPC_errno retval;
83 
85 
86  retval = hipcUsocAcceptSimple(so_p, &HIPCUD_CFGled_SCFG);
87  if (HIPC_SUCCESS != retval) {
88  hipcGenmdQuit(&mdQ, retval, "Failed to accept");
89  } else {
90  retval = hipcsvsLedRun(so_p, &mdQ);
91  }
92 
93  if ((HIPC_ERR_S_IO_READ != retval) && (HIPC_ERR_S_IO_WRITE != retval)) {
94  hipcUsocWriteMsgd(so_p, &mdQ);
95  }
96 
97  return;
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
void hipcsvsLedInit(void)
Definition: hipcsvs_led.c:13
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
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
unsigned char hipcMsgdStruno(hipc_msgd const *const md_p)
Returns structure number of a HIPC message data.
Definition: msgd.c:31
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
enum HIPC_errno hipcsvsLedRun(struct HIPC_usoc *const so_p, hipc_msgd *const mdq_p)
Definition: hipcsvs_led.c:21
Definition: usoc.h:4
void hipcMain(struct HIPC_usoc *const so_p)
Definition: hipcsvs_led.c:79
#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
#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
static struct STRUprm prm
Definition: hipcsvs_led.c:11