gusimplewhiteboard
Whiteboard.h
Go to the documentation of this file.
1/*
2 * Whiteboard.h
3 *
4 * Created by René Hexel on 21/12/11.
5 * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2019 Rene Hexel.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials
18 * provided with the distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgement:
22 *
23 * This product includes software developed by Rene Hexel.
24 *
25 * 4. Neither the name of the author nor the names of contributors
26 * may be used to endorse or promote products derived from this
27 * software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
33 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
35 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
36 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * -----------------------------------------------------------------------
42 * This program is free software; you can redistribute it and/or
43 * modify it under the above terms or under the terms of the GNU
44 * General Public License as published by the Free Software Foundation;
45 * either version 2 of the License, or (at your option) any later version.
46 *
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
51 *
52 * You should have received a copy of the GNU General Public License
53 * along with this program; if not, see http://www.gnu.org/licenses/
54 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
55 * Fifth Floor, Boston, MA 02110-1301, USA.
56 *
57 */
58#ifndef gusimplewhiteboard_Whiteboard_h
59#define gusimplewhiteboard_Whiteboard_h
60
61#include <dispatch/dispatch.h>
62#include <string>
63#include <vector>
64#include <iostream>
65#include <gu_util.h>
66#include "gusimplewhiteboard.h"
67#include "WhiteboardConstants.h"
68#include "WBFunctor.h"
69#include "WBMsg.h"
70
71#ifndef FROM_WHITEBOARD_CC_
72#ifdef __clang__
73#pragma clang diagnostic push
74#pragma clang diagnostic ignored "-Wpedantic"
75#pragma clang diagnostic warning "-W#warnings"
76
77#pragma warning using deprecated whiteboard version
78
79#pragma clang diagnostic pop
80#else
81#pragma message "************************************************************"
82#pragma message "*** using deprecated whiteboard version " __FILE__ "***"
83#pragma message "************************************************************"
84#endif
85#endif // FROM_WHITEBOARD_CC_
86
87#ifdef WHITEBOARD_OLD_H
88#error *** Error: attempt to mix old and simple Whiteboard!
89#endif
90#ifdef _BOOST_WHITEBOARD_H_
91#error *** Error: attempt to mix boost and simple Whiteboard!
92#endif
93
94#define NEW_MSG_ID -1
95#define GLOBAL_MSG_ID 0
96
97namespace guWhiteboard
98{
103 typedef struct gsw_hash_info
104 {
108 gsw_hash_info(int offset) { msg_offset = offset; }
111
116 {
117 public:
119 {
120 int type;
123
125 callback_descr(WBFunctorBase *f, int t = -1, int o = -1): type(t), current(o), func(f) {}
126 };
127 private:
128 dispatch_group_t callback_group;
129 dispatch_queue_t callback_queue;
130 std::vector<callback_descr> _sub;
131 u_int8_t cball_indexes[GSW_TOTAL_MESSAGE_TYPES];
132
134 int getTypeOffset_private(std::string type);
135 public:
144 Whiteboard(const char *sharedMemoryObjectName = gsw_global_whiteboard_name, bool checkVersion = true, int number = 0);
145
150 virtual ~Whiteboard();
151
160 void addMessage(gsw_hash_info *hashinfo, const WBMsg &msg, bool nonatomic=false, bool notifySubscribers=true);
161
166 typedef enum wb_method_result
167 {
171
179 WBMsg getMessage(gsw_hash_info *hashinfo, WBResult *result = NULLPTR);
180
184 void subscriptionCallback(void);
185
193 virtual void subscribeToMessage(gsw_hash_info *hashinfo, WBFunctorBase *func, WBResult &result);
194
201 void unsubscribeToMessage(gsw_hash_info *hashinfo, WBResult &result);
202
208 gsw_hash_info *getTypeOffset(std::string type);
209
214 {
215 switch (m->wbmsg.type)
216 {
217 case WBMsg::TypeBool:
218 return WBMsg(static_cast<bool>(m->sint));
219
220 case WBMsg::TypeInt:
221 return WBMsg(m->sint);
222
223 case WBMsg::TypeFloat:
224 return WBMsg(m->sfloat);
225
227 return WBMsg(m->wbmsg.data);
228
230 return WBMsg(m->wbmsg.data, m->wbmsg.len);
231
232 case WBMsg::TypeArray:
233 {
234 std::vector<int> *v = new std::vector<int>();
235 for (int i = 0; i < m->wbmsg.len; i++)
236 v->push_back(m->ivec[i]);
237 return WBMsg(v, true);
238 }
239 default:
240 return WBMsg();
241 }
242 /* NOTREACHED */
243 }
244
245
246
247
248
249
258 void addMessage(const std::string &type, const WBMsg &msg, bool nonatomic=false, bool notifySubscribers=true);
259
267 WBMsg getMessage(std::string type, WBResult *result = NULLPTR);
268
269
277 virtual void subscribeToMessage(const std::string &type, WBFunctorBase *func, WBResult &result);
278
285 void unsubscribeToMessage(std::string type, WBResult &result);
286
287 };
288}
289
290#endif
#define NEW_MSG_ID
Definition: Whiteboard.h:94
Base class for WBFunctor.
Definition: WBFunctor.h:41
Old WB class for storing shared data.
Definition: WBMsg.h:86
@ TypeString
Definition: WBMsg.h:97
@ TypeBinary
Definition: WBMsg.h:99
@ TypeFloat
Definition: WBMsg.h:96
@ TypeBool
Definition: WBMsg.h:94
@ TypeArray
Definition: WBMsg.h:98
@ TypeInt
Definition: WBMsg.h:95
compatibility API for accessing the whiteboard
Definition: Whiteboard.h:116
WBMsg getMessage(gsw_hash_info *hashinfo, WBResult *result=NULLPTR)
Get Message Gets a message from a simple whiteboard.
Definition: Whiteboard.cc:194
void unsubscribeToMessage(gsw_hash_info *hashinfo, WBResult &result)
Unsubscribe To Message (sic!) Unsubscribes from a message type on a whiteboard or whiteboards.
Definition: Whiteboard.cc:305
gu_simple_whiteboard_descriptor * _wbd
underlying whiteboard
Definition: Whiteboard.h:136
virtual void subscribeToMessage(gsw_hash_info *hashinfo, WBFunctorBase *func, WBResult &result)
Subscribe To Message Subscribes to a message type on a whiteboard or whiteboards.
Definition: Whiteboard.cc:227
Whiteboard(const char *sharedMemoryObjectName=gsw_global_whiteboard_name, bool checkVersion=true, int number=0)
API Constructor This sets up the API and the callback soap server.
Definition: Whiteboard.cc:91
static WBMsg getWBMsg(gu_simple_message *m)
convert the new 'simple' whiteboard data structure into the old WBMsg format
Definition: Whiteboard.h:213
gsw_hash_info * getTypeOffset(std::string type)
create a hash offset from message type, needed for adding, getting from WB
Definition: Whiteboard.cc:210
wb_method_result
Return Type Enum.
Definition: Whiteboard.h:167
@ METHOD_OK
No errors detected.
Definition: Whiteboard.h:168
@ METHOD_FAIL
Errors detected.
Definition: Whiteboard.h:169
void addMessage(gsw_hash_info *hashinfo, const WBMsg &msg, bool nonatomic=false, bool notifySubscribers=true)
Add Message Adds a message to the whiteboard that the API is connected to.
Definition: Whiteboard.cc:130
enum guWhiteboard::Whiteboard::wb_method_result WBResult
Return Type Enum.
void subscriptionCallback(void)
subscription callback: not really public!
Definition: Whiteboard.cc:267
virtual ~Whiteboard()
Destructor.
Definition: Whiteboard.cc:119
#define GSW_TOTAL_MESSAGE_TYPES
message types (max)
#define u_int8_t
const char * gsw_global_whiteboard_name
global whiteboard name
Definition: Whiteboard.cc:78
/file APM_Interface.h
struct guWhiteboard::gsw_hash_info gsw_hash_info
Message offset holder.
the underlying whiteboard object
WBFunctorBase * func
functor to call
Definition: Whiteboard.h:122
callback_descr(WBFunctorBase *f, int t=-1, int o=-1)
create callback descr
Definition: Whiteboard.h:125
Message offset holder.
Definition: Whiteboard.h:104
gsw_hash_info(int offset)
create with real index value
Definition: Whiteboard.h:108
gsw_hash_info()
create object with default value for index
Definition: Whiteboard.h:106
int msg_offset
the index value to store
Definition: Whiteboard.h:109
union type that is used to store data in shared memory
float sfloat
signed float
int ivec[128/sizeof(int)]
int array
struct gsw_simple_message::@4 wbmsg
compatibility WBMsg type
int sint
signed integer