TUIO C++ Developer API
FlashSender.h
1 //
2 // TFFlashLCSHMEM.h
3 // Touché
4 //
5 // Created by Georg Kaindl on 16/3/09.
6 //
7 // Copyright (C) 2009 Georg Kaindl
8 //
9 // This file is part of Touché.
10 //
11 // Touché is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU Lesser General Public License as
13 // published by the Free Software Foundation, either version 3 of
14 // the License, or (at your option) any later version.
15 //
16 // Touché is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with Touché. If not, see <http://www.gnu.org/licenses/>.
23 
24 
25 #if !defined(__TFFlashLCSHMEM_H__)
26 #define __TFFlashLCSHMEM_H__ 1
27 
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif /* __cplusplus */
32 
33 #ifdef WIN32
34 #include <windows.h>
35 typedef DWORD u_int32_t;
36 #else
37 #include <sys/types.h>
38 #include <semaphore.h>
39 #endif
40 
41 #define TFLCS_LISTENER_NAME_MAX_LEN (64)
42 #define TFLCS_LISTENER_METHOD_MAX_LEN (64)
43 
44  typedef struct TFLCSLocalConnection_t {
45 #ifdef WIN32
46  HANDLE semaphore;
47  HANDLE mapFile;
48  LPVOID mapAddress;
49 #else
50  int shmid;
51  sem_t* semaphore;
52 #endif
53  int open;
54  char* data;
55  char listenerName[TFLCS_LISTENER_NAME_MAX_LEN];
56  char listenerMethod[TFLCS_LISTENER_METHOD_MAX_LEN];
58 
59  typedef enum {
60  TFLCSErrorSuccess = 0,
61  TFLCSErrorInvalidArgument = 1,
62  TFLCSErrorShmemKeyNotFound = 2,
63  TFLCSErrorSemaphoreCreationFailed = 3,
64  TFLCSErrorShmemIDNotFound = 4,
65  TFLCSErrorShmemOpeningFailed = 5,
66  TFLCSErrorOutOfMemory = 6
67  } TFLCSError_t;
68 
69  // much like errno, this will hold the last error that happened
70  extern TFLCSError_t TFLCSErrno;
71 
72  // connect to a Flash LocalConnection
73  // returns pointer to structure on success, NULL otherwise
74  // if the connection could not be opened right away (because Flash is not yet running),
75  // a non-null pointer is returned, but the "open" member of the structure will be 0
76  // and TFLCSErrno will be set accordingly. the connection is truly open once "open" is
77  // non-zero.
78  TFLCSLocalConnection_t* TFLCSConnect(const char* listenerName,
79  const char* listenerMethod,
80  void* shmemKey,
81  void* semaphoreKey);
82 
83  // disconnect a Flash LocalConnection
84  void TFLCSDisconnect(TFLCSLocalConnection_t* connection);
85 
86  // changes the connection listener name
87  void TFLCSChangeListenerName(TFLCSLocalConnection_t* connection, const char* newListenerName);
88 
89  // changes the connection method name
90  void TFLCSChangeMethodName(TFLCSLocalConnection_t* connection, const char* newMethodName);
91 
92  // returns non-zero if the given connection's Flash client is connected, 0 otherwise
93  int TFLCSConnectionHasConnectedClient(TFLCSLocalConnection_t* connection);
94 
95  // tries to determine the key for the shared memory region used by the Flash LocalConnection
96  // returns a pointer to static memory on success, NULL on error.
97  void* TFLCSGuessShmemKey();
98 
99  // get the current tick count (milliseconds since the system was started)
100  u_int32_t TFLCSGetTickCount();
101 
102  // write an AMF3-encoded integer into a buffer
103  // returns the updated buffer position
104  int TFLCSWriteAMF3Integer(char* buffer, int value, int pos);
105 
106  // write an AMF-encoded string into a buffer
107  // returns the updated buffer position
108  int TFLCSWriteAMFString(char* buffer, const char * str, int pos);
109 
110  // write an AMF3-encoded byte array into a buffer
111  // returns the updated buffer position
112  int TFLCSWriteAMF3ByteArray(char* buffer, const char* bytes, int pos, int len);
113 
114  // writes the AMF envelope header for an LC method call
115  // returns the position in the buffer
116  int TFLCSWriteLCAMFEnvelopeHeader(TFLCSLocalConnection_t* connection);
117 
118  // writes the AMF envelope trailer for an LC method call
119  // returns the updated buffer position
120  int TFLCSWriteLCAMFEnvelopeTrailer(TFLCSLocalConnection_t* connection, int pos);
121 
122  // sends the given data of length len over the given connection as a ByteArray
123  // returns 1 on success, 0 otherwise
124  int TFLCSSendByteArray(TFLCSLocalConnection_t* connection, const char* bytes, int len);
125 
126  // gets the (string) names of all connected LC connections
127  // returns the number of found strings.
128  int TFLCSGetConnectedConnectionNames(TFLCSLocalConnection_t* connection, char* dest, int destLen);
129 
130  // dumps a given buffer (size bytes starting at offset) to stdout in a nice hex/ascii format.
131  // useful for debugging purposes.
132  void TFLCSDumpMemory(char* buffer, int offset, int size);
133 
134 #ifdef __cplusplus
135 }
136 #endif /* __cplusplus */
137 #endif //__TFFlashLCSHMEM_H__
138 
139 /*
140  TUIO C++ Library
141  Copyright (c) 2005-2017 Martin Kaltenbrunner <martin@tuio.org>
142 
143  This library is free software; you can redistribute it and/or
144  modify it under the terms of the GNU Lesser General Public
145  License as published by the Free Software Foundation; either
146  version 3.0 of the License, or (at your option) any later version.
147 
148  This library is distributed in the hope that it will be useful,
149  but WITHOUT ANY WARRANTY; without even the implied warranty of
150  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
151  Lesser General Public License for more details.
152 
153  You should have received a copy of the GNU Lesser General Public
154  License along with this library.
155 */
156 
157 #ifndef INCLUDED_FLASHSENDER_H
158 #define INCLUDED_FLASHSENDER_H
159 
160 #include "OscSender.h"
161 
162 #define MAX_FLASH_SIZE (40976)
163 #define DEFAULT_LC_CONN_NAME "_OscDataStream"
164 #define DEFAULT_LC_METH_NAME "receiveOscData"
165 
166 namespace TUIO {
167 
174  class LIBDECL FlashSender : public OscSender {
175 
176  public:
177 
181  FlashSender();
182 
186  FlashSender(const char *conn_name, const char *meth_name);
187 
191  virtual ~FlashSender();
192 
200  bool sendOscPacket (osc::OutboundPacketStream *bundle);
201 
207  bool isConnected ();
208 
209  const char* tuio_type() { return "TUIO/FLC"; }
210 
211  private:
212  TFLCSLocalConnection_t* lcConnection;
213  };
214 }
215 #endif /* INCLUDED_FLASHSENDER_H */
Definition: FlashSender.h:44
Definition: FlashSender.h:166
Definition: OscSender.h:37
Definition: FlashSender.h:174