HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
main_posix.c
Go to the documentation of this file.
1 #include <unistd.h>
2 
3 #include <errno.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <pthread.h>
7 
8 #include <hipc/posix/ioutils.h>
9 #include <hipc/posix/usoc.h>
10 
11 #include "CFGrt.h"
12 #include "hipcsvs_rt.h"
13 
14 static void *runMockServer(void *arg)
15 {
16  struct HIPC_pbank *const pbank_p = &hipcsvsRt_pbank;
17  struct STRUprm const *prm_p;
18 
19  for (;;) {
20  hipcPbankSwitchAccept(pbank_p);
21  prm_p = hipcPbankGetReadOnlyPage(pbank_p);
22  fprintf(stderr, "led:%d\n", prm_p->led);
23  usleep(1000 * 1000);
24  }
25 
26  pthread_exit(NULL);
27 }
28 
29 int main(void)
30 {
31  pthread_attr_t attr;
32  pthread_t thread;
33  struct HIPC_usoc usoc;
34 
35  hipcPosixUsocInit(&usoc, STDIN_FILENO, STDOUT_FILENO);
36  hipcsvsRtInit();
37 
38  if (0 != pthread_attr_init(&attr)) {
39  perror("pthread_attr_init faild");
40  exit(EXIT_FAILURE);
41  }
42  if (0 != pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) {
43  perror("pthread_attr_setdetachstate faild");
44  exit(EXIT_FAILURE);
45  }
46  if (0 != pthread_create(&thread, &attr, runMockServer, NULL)) {
47  perror("pthread_create faild");
48  exit(EXIT_FAILURE);
49  }
50  if (0 != pthread_attr_destroy(&attr)) {
51  perror("pthread_attr_destroy faild");
52  exit(EXIT_FAILURE);
53  }
54 
55  hipcMain(&usoc);
56 
57  if (0 != errno) {
58  perror("Error message from perror()");
59  fprintf(stderr, "errno: %d\n", errno);
60  }
61  fprintf(stderr, "end\n");
62 
63  return 0;
64 }
void hipcPosixUsocInit(struct HIPC_usoc *so_p, const int fdr, const int fdw)
Initializes a universal socket.
Definition: posix_usoc.c:14
static void * runMockServer(void *arg)
Definition: main_posix.c:14
int main(void)
Definition: main_posix.c:18
const void * hipcPbankGetReadOnlyPage(struct HIPC_pbank *const bank_p)
Gets a current read only page.
Definition: pbank.c:44
Definition: usoc.h:4
void hipcsvsRtInit(void)
Definition: hipcsvs_rt.c:15
void hipcMain(struct HIPC_usoc *const so_p)
Definition: server.c:68
struct HIPC_pbank hipcsvsRt_pbank
Definition: hipcsvs_rt.c:13
int hipcPbankSwitchAccept(struct HIPC_pbank *const bank_p)
Accepts a switching request and switches pages if switching is requested.
Definition: pbank.c:96