HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
hipcsvs_rt.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 "CFGrt.h"
8 #include "CFGrt_scfg.h"
9 #include "hipcsvs_rt.h"
10 
11 #define PBANK_PAGE_SIZE sizeof(struct STRUprm)
12 
14 
15 void hipcsvsRtInit(void)
16 {
17  static struct STRUprm bufprm[2];
18 
19  bufprm[0].led = 0;
21 
22  return;
23 }
24 
25 enum HIPC_errno hipcsvsRtRun(struct HIPC_usoc *const so_p,
26  hipc_msgd * const mdq_p)
27 {
28  hipc_msgd mdR;
29  hipc_msgd mdS;
30  enum HIPC_errno retval;
31  struct HIPC_pbank *const pbank_p = &hipcsvsRt_pbank;
32  struct STRUprm *prm_p;
33 
34  for (;;) {
35  retval =
37  if (HIPC_SUCCESS != retval) {
38  return hipcGenmdQuit(mdq_p, retval, "Header");
39  }
40 
41  switch (hipcMsgdType(&mdR)) {
43  return hipcGenmdQuit(mdq_p, HIPC_SUCCESS, NULL);
45  if (HIPCUD_STRUprm != hipcMsgdStruno(&mdR)) {
47  "GETc0");
48  }
49  if (HIPC_PBANK_STAT_GROUND != hipcPbankGetStat(pbank_p)) {
51  "GETc1");
52  }
53  retval =
54  hipcGenmdSuccessToGet(&mdS, &mdR,
55  hipcPbankGetWritablePage(pbank_p),
57  if (HIPC_SUCCESS != retval) {
58  return hipcGenmdQuit(mdq_p, retval, "GETr");
59  }
60  break;
62  if (HIPCUD_STRUprm != hipcMsgdStruno(&mdR)) {
64  "PUTc0");
65  }
66  if (HIPC_PBANK_STAT_GROUND != hipcPbankGetStat(pbank_p)) {
68  "PUTc1");
69  }
70 
71  prm_p = hipcPbankGetWritablePage(pbank_p);
72  retval = hipcMsgdSetBdyForPut(&mdR, prm_p, PBANK_PAGE_SIZE);
73  if (HIPC_SUCCESS != retval) {
74  return hipcGenmdQuit(mdq_p, retval, "PUTs");
75  }
76  retval = hipcUsocRead(so_p, hipcMsgdBdyPtr(&mdR),
77  hipcMsgdBdySize(&mdR));
78  if (HIPC_SUCCESS != retval) {
79  return hipcGenmdQuit(mdq_p, retval, "PUTb");
80  }
81 
82  if (1 < prm_p->led) {
83  return hipcGenmdQuit(mdq_p, HIPC_ERR_S_INV_UDATA,
84  "1 < prm.led");
85  }
86 
87  retval = hipcPbankSwitchReqWaitCmpl(pbank_p);
88  if (HIPC_SUCCESS != retval) {
89  return hipcGenmdQuit(mdq_p, retval, "pbank");
90  }
91 
92  hipcGenmdSuccess(&mdS);
93  break;
94  default:
95  return hipcGenmdQuit(mdq_p, HIPC_ERR_S_INV_MSG_TYPE, NULL);
96  }
97  retval = hipcUsocWriteMsgd(so_p, &mdS);
98  if (HIPC_SUCCESS != retval) {
99  return hipcGenmdQuit(mdq_p, retval, "RESP");
100  }
101  }
102 }
103 
104 void hipcMain(struct HIPC_usoc *const so_p)
105 {
106  hipc_msgd mdQ;
107  enum HIPC_errno retval;
108 
110 
111  retval = hipcUsocAcceptSimple(so_p, &HIPCUD_CFGrt_SCFG);
112  if (HIPC_SUCCESS != retval) {
113  hipcGenmdQuit(&mdQ, retval, "Failed to accept");
114  } else {
115  retval = hipcsvsRtRun(so_p, &mdQ);
116  }
117 
118  if ((HIPC_ERR_S_IO_READ != retval) && (HIPC_ERR_S_IO_WRITE != retval)) {
119  hipcUsocWriteMsgd(so_p, &mdQ);
120  }
121 
122  return;
123 }
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 hipcPbankSwitchReqWaitCmpl(struct HIPC_pbank *const bank_p)
Calls hipcPbankSwitchRequest(), waits for acceptance of the request, and calls hipcPbankSwitchComplet...
Definition: pbank.c:141
void * hipcPbankGetWritablePage(struct HIPC_pbank *const bank_p)
Gets a current writable page.
Definition: pbank.c:55
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 hipcsvsRtRun(struct HIPC_usoc *const so_p, hipc_msgd *const mdq_p)
Definition: hipcsvs_rt.c:25
#define PBANK_PAGE_SIZE
Definition: hipcsvs_rt.c:11
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_pbank_stat hipcPbankGetStat(struct HIPC_pbank *const bank_p)
Gets current status of a bank.
Definition: pbank.c:66
Definition: usoc.h:4
void hipcPbankInit(struct HIPC_pbank *const bank_p, void *const buf_p, const size_t page_size)
Initializes a parameter bank.
Definition: pbank.c:14
#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 hipcsvsRtInit(void)
Definition: hipcsvs_rt.c:15
#define hipcMsgdHdrPtr(md_p)
Returns a pointer to a header of a HIPC message data.
Definition: msgd.h:44
struct HIPC_pbank hipcsvsRt_pbank
Definition: hipcsvs_rt.c:13
void hipcMain(struct HIPC_usoc *const so_p)
Definition: hipcsvs_rt.c:104