POK
/home/jaouen/pok_official/pok/trunk/libpok/middleware/blackboardcreate.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Thu Jan 15 23:34:13 2009 
00015  */
00016 
00017 #include <core/dependencies.h>
00018 
00019 #ifdef POK_NEEDS_MIDDLEWARE
00020 #ifdef POK_NEEDS_BLACKBOARDS
00021 
00022 #include <errno.h>
00023 #include <types.h>
00024 #include <libc/string.h>
00025 #include <core/event.h>
00026 #include <middleware/blackboard.h>
00027 
00028 extern pok_blackboard_t    pok_blackboards[POK_CONFIG_NB_BLACKBOARDS];
00029 extern char*               pok_blackboards_names[POK_CONFIG_NB_BLACKBOARDS];
00030 pok_size_t                 pok_blackboards_data_index = 0;
00031 
00032 pok_ret_t pok_blackboard_create (char*                             name, 
00033                                  const pok_port_size_t             msg_size, 
00034                                  pok_blackboard_id_t*              id)
00035 {
00036    pok_ret_t   ret;
00037    uint8_t     n;
00038 
00039    for (n=0 ; n < POK_CONFIG_NB_BLACKBOARDS ; n++)
00040    {
00041       if (streq (name, pok_blackboards_names[n]))
00042       {
00043          if (pok_blackboards[n].ready == TRUE)
00044          {
00045             return POK_ERRNO_READY;
00046          }
00047 
00048          ret = pok_event_create (&pok_blackboards[n].lock);
00049 
00050          if (ret != POK_ERRNO_OK)
00051          {
00052             return ret;
00053          }
00054 
00055          pok_blackboards[n].ready               = TRUE;
00056          pok_blackboards[n].empty               = TRUE;
00057          pok_blackboards[n].index               = pok_blackboards_data_index;
00058          pok_blackboards[n].waiting_processes   = 0;
00059          pok_blackboards[n].size                = msg_size;
00060          *id                                    = n;
00061          pok_blackboards_data_index             = pok_blackboards_data_index + msg_size;
00062          return POK_ERRNO_OK;
00063       }
00064    }
00065 
00066    return POK_ERRNO_EINVAL;
00067 }
00068 
00069 #endif /* POK_NEEDS_BLACKBOARDS */
00070 #endif /* POK_NEEDS_MIDDLEWARE */