POK
buffercreate.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 #include <core/dependencies.h>
18 
19 #ifdef POK_NEEDS_MIDDLEWARE
20 #ifdef POK_NEEDS_BUFFERS
21 
22 #include <errno.h>
23 #include <types.h>
24 #include <core/time.h>
25 #include <core/event.h>
26 #include <libc/string.h>
27 #include <middleware/buffer.h>
28 
29 extern pok_buffer_t pok_buffers[POK_CONFIG_NB_BUFFERS];
30 extern char* pok_buffers_names[POK_CONFIG_NB_BUFFERS];
31 pok_size_t pok_buffers_data_index = 0;
32 
33 
34 pok_ret_t pok_buffer_create (char* name,
35  const pok_port_size_t size,
36  const pok_port_size_t msg_size,
37  const pok_queueing_discipline_t discipline,
38  pok_buffer_id_t* id)
39 {
40  uint8_t n;
41  pok_ret_t ret;
42 
43  for (n=0 ; n < POK_CONFIG_NB_BUFFERS ; n++)
44  {
45  if (streq (name, pok_buffers_names[n]))
46  {
47  if (pok_buffers[n].ready == TRUE)
48  {
49  return POK_ERRNO_READY;
50  }
51 
52  ret = pok_event_create (&pok_buffers[n].lock);
53 
54  if (ret != POK_ERRNO_OK)
55  {
56  return ret;
57  }
58 
59  pok_buffers[n].index = pok_buffers_data_index;
60  pok_buffers[n].ready = TRUE;
61  pok_buffers[n].empty = TRUE;
62  pok_buffers[n].size = size;
63  pok_buffers[n].msgsize = msg_size;
64  pok_buffers[n].waiting_processes = 0;
65  pok_buffers[n].off_e = 0;
66  pok_buffers[n].off_b = 0;
67  pok_buffers[n].discipline = discipline;
68 
69  pok_buffers_data_index = pok_buffers_data_index + size;
70 
71  *id = n;
72 
73  return POK_ERRNO_OK;
74  }
75 
76  }
77 
78  return POK_ERRNO_EINVAL;
79 }
80 
81 #endif /* POK_NEEDS_BUFFERS */
82 #endif /* POK_NEEDS_MIDDLEWARE */