POK
blackboardcreate.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_BLACKBOARDS
21 
22 #include <errno.h>
23 #include <types.h>
24 #include <libc/string.h>
25 #include <core/event.h>
26 #include <middleware/blackboard.h>
27 
28 extern pok_blackboard_t pok_blackboards[POK_CONFIG_NB_BLACKBOARDS];
29 extern char* pok_blackboards_names[POK_CONFIG_NB_BLACKBOARDS];
30 pok_size_t pok_blackboards_data_index = 0;
31 
32 pok_ret_t pok_blackboard_create (char* name,
33  const pok_port_size_t msg_size,
34  pok_blackboard_id_t* id)
35 {
36  pok_ret_t ret;
37  uint8_t n;
38 
39  for (n=0 ; n < POK_CONFIG_NB_BLACKBOARDS ; n++)
40  {
41  if (streq (name, pok_blackboards_names[n]))
42  {
43  if (pok_blackboards[n].ready == TRUE)
44  {
45  return POK_ERRNO_READY;
46  }
47 
48  ret = pok_event_create (&pok_blackboards[n].lock);
49 
50  if (ret != POK_ERRNO_OK)
51  {
52  return ret;
53  }
54 
55  pok_blackboards[n].ready = TRUE;
56  pok_blackboards[n].empty = TRUE;
57  pok_blackboards[n].index = pok_blackboards_data_index;
58  pok_blackboards[n].waiting_processes = 0;
59  pok_blackboards[n].size = msg_size;
60  *id = n;
61  pok_blackboards_data_index = pok_blackboards_data_index + msg_size;
62  return POK_ERRNO_OK;
63  }
64  }
65 
66  return POK_ERRNO_EINVAL;
67 }
68 
69 #endif /* POK_NEEDS_BLACKBOARDS */
70 #endif /* POK_NEEDS_MIDDLEWARE */