Helixis 1.0
Task Programming API
sources/internal_includes/native/native_channels.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2009-2011, helixis.org
00003 ** All rights reserved.
00004 **
00005 ** Redistribution and use in source and binary forms, with or without modification, are permitted provided
00006 ** that the following conditions are met:
00007 **
00008 ** Redistributions of source code must retain the above copyright notice, this list of conditions and the
00009 ** following disclaimer.
00010 **
00011 ** Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
00012 ** the following disclaimer in the documentation and/or other materials provided with the distribution.
00013 **
00014 ** Neither the name of the helixis.org nor the names of its contributors may be used to endorse or promote
00015 ** products derived from this software without specific prior written permission.
00016 **
00017 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00018 ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00019 ** PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00020 ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00021 ** TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00023 ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00024 ** POSSIBILITY OF SUCH DAMAGE.
00025 */
00026 
00027 #ifndef __HLX_NATIVE_CHANNELS_H__
00028 # define __HLX_NATIVE_CHANNELS_H__
00029 
00030 #if !defined(HLX_BUILD_WITH_PARALLEL_THREADING)
00031 
00032 #ifdef __cplusplus
00033 extern "C"      {
00034 #endif
00035 
00036 /*
00037 ** MACROS
00038 */
00039 
00040 # define HLX_CHAN_AVAILABLE             (0)
00041 # define HLX_CHAN_FILLED                (3)
00042 
00043 # define HLX_CHAN_WRITE_GENERATOR(name, type, union_var)        \
00044 int             __hlx_chan_write_##name(unsigned long id, type value)   \
00045 {       \
00046         hlx_list_node           *node;  \
00047         _hlx_channel            *chan;  \
00048         \
00049         if ((node = _hlx_get_channel_by_hash(id)) == 0) \
00050            return (0);  \
00051     chan = (_hlx_channel *)node->data;  \
00052         if (chan->status != HLX_CHAN_AVAILABLE) \
00053            return (0);  \
00054         chan->data.union_var = value;   \
00055     chan->status = HLX_CHAN_FILLED;     \
00056         return (1);     \
00057 }
00058 
00059 # define HLX_CHAN_READ_GENERATOR(name, type, union_var) \
00060 int             __hlx_chan_read_##name(unsigned long id, type* value)   \
00061 {       \
00062         hlx_list_node           *node;  \
00063         _hlx_channel            *chan;  \
00064         \
00065         if ((node = _hlx_get_channel_by_hash(id)) == 0) \
00066            return (0);  \
00067     chan = (_hlx_channel *)node->data;  \
00068     if (chan->status != HLX_CHAN_FILLED)        \
00069        return (0);      \
00070     *value = chan->data.union_var;      \
00071     chan->status = HLX_CHAN_AVAILABLE;  \
00072     return (1); \
00073 }
00074 
00075 /*
00076 ** TYPES
00077 */
00078 
00079 typedef union
00080 {
00081         char    c;
00082         short   s;
00083         int             i;
00084         float   f;
00085         void*   p;
00086 }       _hlx_channel_data;
00087 
00088 typedef struct
00089 {
00090         _hlx_channel_data       data;
00091         unsigned char           status;
00092         unsigned long           hash_code;
00093 }                                               _hlx_channel;
00094 
00095 typedef struct
00096 {
00097         hlx_list                        channels;
00098 }                                               _hlx_channel_manager;
00099 
00100 /*
00101 ** FUNCTIONS
00102 */
00103 
00104 void    _init_channel_manager(void);
00105 void    _destroy_channel_manager(void);
00106 
00107 #ifdef __cplusplus
00108 }
00109 #endif
00110 
00111 #endif /* HLX_BUILD_WITH_KERNEL_THREAD */
00112 
00113 #endif /* !__HLX_NATIVE_CHANNELS_H__ */
00114 
00115 /*
00116 ** END OF FILE
00117 */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines