v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
event.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * Sifteo SDK
4  *
5  * Copyright <c> 2012 Sifteo, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #pragma once
27 #ifdef NOT_USERSPACE
28 # error This is a userspace-only header, not allowed by the current build.
29 #endif
30 
31 #include <sifteo/abi.h>
32 
33 namespace Sifteo {
34 
35 
55 template <_SYSVectorID tID>
56 struct EventVector {
57  EventVector() {}
58 
66  void unset() const {
67  _SYS_setVector(tID, 0, 0);
68  }
69 
82  template <typename tContext>
83  void set(void (*handler)(tContext, unsigned), tContext context) const {
84  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
85  }
86 
99  void set(void (*handler)(void*, unsigned)) const {
100  _SYS_setVector(tID, (void*) handler, 0);
101  }
102 
107  template <typename tClass>
108  void set(void (tClass::*handler)(unsigned), tClass *cls) const {
109  union {
110  void *pVoid;
111  void (tClass::*pMethod)(unsigned);
112  } u;
113  u.pMethod = handler;
114  _SYS_setVector(tID, u.pVoid, (void*) cls);
115  }
116 
120  void *handler() const {
121  return _SYS_getVectorHandler(tID);
122  }
123 
127  void *context() const {
128  return _SYS_getVectorContext(tID);
129  }
130 };
131 
132 
144 template <_SYSVectorID tID>
146  NullaryEventVector() {}
147 
155  void unset() const {
156  _SYS_setVector(tID, 0, 0);
157  }
158 
167  template <typename tContext>
168  void set(void (*handler)(tContext), tContext context) const {
169  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
170  }
171 
179  void set(void (*handler)()) const {
180  _SYS_setVector(tID, (void*) handler, 0);
181  }
182 
187  template <typename tClass>
188  void set(void (tClass::*handler)(), tClass *cls) const {
189  union {
190  void *pVoid;
191  void (tClass::*pMethod)();
192  } u;
193  u.pMethod = handler;
194  _SYS_setVector(tID, u.pVoid, (void*) cls);
195  }
196 
200  void *handler() const {
201  return _SYS_getVectorHandler(tID);
202  }
203 
207  void *context() const {
208  return _SYS_getVectorContext(tID);
209  }
210 };
211 
212 
222 
228  void unset() const {
229  _SYS_setGameMenuLabel(0);
230  _SYS_setVector(_SYS_BASE_GAME_MENU, 0, 0);
231  }
232 
244  template <typename tContext>
245  void set(void (*handler)(tContext), tContext context, const char *label=0) const {
246  if (label)
247  _SYS_setGameMenuLabel(label);
248  _SYS_setVector(_SYS_BASE_GAME_MENU, (void*) handler, reinterpret_cast<void*>(context));
249  }
250 
262  void set(void (*handler)(void*), const char *label=0) const {
263  if (label)
264  _SYS_setGameMenuLabel(label);
265  _SYS_setVector(_SYS_BASE_GAME_MENU, (void*) handler, 0);
266  }
267 
275  template <typename tClass>
276  void set(void (tClass::*handler)(), tClass *cls, const char *label=0) const {
277  union {
278  void *pVoid;
279  void (tClass::*pMethod)();
280  } u;
281  u.pMethod = handler;
282  if (label)
283  _SYS_setGameMenuLabel(label);
284  _SYS_setVector(_SYS_BASE_GAME_MENU, u.pVoid, (void*) cls);
285  }
286 
290  void *handler() const {
291  return _SYS_getVectorHandler(_SYS_BASE_GAME_MENU);
292  }
293 
297  void *context() const {
298  return _SYS_getVectorContext(_SYS_BASE_GAME_MENU);
299  }
300 
312  void setLabel(const char *label) const {
313  ASSERT(label && label[0]);
314  _SYS_setGameMenuLabel(label);
315  }
316 
322  void setResumeEnabled(bool enabled) const {
323  _SYS_setPauseMenuResumeEnabled(enabled);
324  }
325 };
326 
327 
335 template <_SYSVectorID tID>
338 
346  void unset() const {
347  _SYS_setVector(tID, 0, 0);
348  }
349 
362  template <typename tContext>
363  void set(void (*handler)(tContext, unsigned, unsigned, unsigned, unsigned), tContext context) const {
364  _SYS_setVector(tID, (void*) handler, reinterpret_cast<void*>(context));
365  }
366 
379  void set(void (*handler)(void*, unsigned, unsigned, unsigned, unsigned)) const {
380  _SYS_setVector(tID, (void*) handler, 0);
381  }
382 
387  template <typename tClass>
388  void set(void (tClass::*handler)(unsigned, unsigned, unsigned, unsigned), tClass *cls) const {
389  union {
390  void *pVoid;
391  void (tClass::*pMethod)(unsigned, unsigned, unsigned, unsigned);
392  } u;
393  u.pMethod = handler;
394  _SYS_setVector(tID, u.pVoid, (void*) cls);
395  }
396 
400  void *handler() const {
401  return _SYS_getVectorHandler(tID);
402  }
403 
407  void *context() const {
408  return _SYS_getVectorContext(tID);
409  }
410 };
411 
412 
431 namespace Events {
432 
433  /*
434  * Neighboring events
435  */
436 
439 
442 
443  /*
444  * Cube events
445  */
446 
456 
470 
473 
476 
479 
482 
496 
497  /*
498  * Base events
499  */
500 
503 
506 
509 
512 
513  /*
514  * Bluetooth events
515  */
516 
519 
522 
525 
528 
529  /*
530  * USB events
531  */
532 
535 
538 
541 
544 
545 }; // namespace Events
546 
551 }; // namespace Sifteo
void set(void(*handler)(tContext, unsigned), tContext context) const
Set this Vector to a function with context pointer.
Definition: event.h:83
const NullaryEventVector< _SYS_BASE_USB_CONNECT > usbConnect
The Sifteo Base has established a connection with the host's USB.
Definition: event.h:534
void set(void(*handler)()) const
Set this Vector to a bare function.
Definition: event.h:179
void set(void(tClass::*handler)(), tClass *cls, const char *label=0) const
Set this event vector to an instance method, given a class method pointer and an instance of that cla...
Definition: event.h:276
const NullaryEventVector< _SYS_BASE_USB_WRITE_AVAILABLE > usbWriteAvailable
Buffer space just became available for writing to the UsbPipe.
Definition: event.h:543
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
const NullaryEventVector< _SYS_BASE_USB_READ_AVAILABLE > usbReadAvailable
Packets are available for reading on the UsbPipe.
Definition: event.h:540
const EventVector< _SYS_BASE_VOLUME_DELETE > volumeDelete
A filesystem Volume was deleted.
Definition: event.h:508
const NullaryEventVector< _SYS_BASE_BT_READ_AVAILABLE > bluetoothReadAvailable
Packets are available for reading on the current BluetoothPipe.
Definition: event.h:524
const NullaryEventVector< _SYS_BASE_BT_WRITE_AVAILABLE > bluetoothWriteAvailable
Buffer space just became available for writing to the current BluetoothPipe.
Definition: event.h:527
void * handler() const
Return the currently set handler function, as a void pointer.
Definition: event.h:200
const EventVector< _SYS_BASE_TRACKER > baseTracker
An event generated by Sifteo::AudioTracker.
Definition: event.h:502
const EventVector< _SYS_BASE_VOLUME_COMMIT > volumeCommit
A filesystem Volume was committed and is now available to read.
Definition: event.h:511
const GameMenuEventVector gameMenu
An event generated by an optional custom "game menu" item on the standard pause menu.
Definition: event.h:505
void setResumeEnabled(bool enabled) const
Specify whether the 'Resume' option should be included in the menu.
Definition: event.h:322
void * context() const
Return the currently set context object, as a void pointer.
Definition: event.h:297
Implementation for a single neighbor event vector.
Definition: event.h:336
const NullaryEventVector< _SYS_BASE_BT_CONNECT > bluetoothConnect
A mobile device has established a connection with the Sifteo Bluetooth API.
Definition: event.h:518
const EventVector< _SYS_CUBE_TOUCH > cubeTouch
A cube's touch state has changed (touch began or ended).
Definition: event.h:478
void set(void(*handler)(void *), const char *label=0) const
Set this Vector to a bare function.
Definition: event.h:262
void * context() const
Return the currently set context object, as a void pointer.
Definition: event.h:127
const NullaryEventVector< _SYS_BASE_BT_DISCONNECT > bluetoothDisconnect
A mobile device has disconnected from the Sifteo Bluetooth API.
Definition: event.h:521
void set(void(tClass::*handler)(unsigned, unsigned, unsigned, unsigned), tClass *cls) const
Set this event vector to an instance method, given a class method pointer and an instance of that cla...
Definition: event.h:388
void * handler() const
Return the currently set handler function, as a void pointer.
Definition: event.h:290
void * context() const
Return the currently set context object, as a void pointer.
Definition: event.h:207
const NeighborEventVector< _SYS_NEIGHBOR_REMOVE > neighborRemove
One neighbor connection has been dissolved.
Definition: event.h:441
const EventVector< _SYS_CUBE_ASSETDONE > cubeAssetDone
The current AssetConfiguration has finished loading on this cube.
Definition: event.h:472
void set(void(*handler)(void *, unsigned)) const
Set this Vector to a bare function.
Definition: event.h:99
const EventVector< _SYS_CUBE_BATTERY > cubeBatteryLevelChange
A cube's battery level has changed measurably.
Definition: event.h:481
const NeighborEventVector< _SYS_NEIGHBOR_ADD > neighborAdd
One neighbor connection (cube/side paired with cube/side) has been formed.
Definition: event.h:438
void set(void(*handler)(tContext, unsigned, unsigned, unsigned, unsigned), tContext context) const
Set this Vector to a function with context pointer.
Definition: event.h:363
const EventVector< _SYS_CUBE_DISCONNECT > cubeDisconnect
A formerly connected cube has been lost.
Definition: event.h:469
void set(void(*handler)(tContext), tContext context) const
Set this Vector to a function with context pointer.
Definition: event.h:168
Implementation for an event vector that takes no parameter.
Definition: event.h:145
const NullaryEventVector< _SYS_BASE_USB_DISCONNECT > usbDisconnect
The Sifteo Base has been disconnected from the host's USB.
Definition: event.h:537
void set(void(*handler)(tContext), tContext context, const char *label=0) const
Set this Vector to a function with context pointer.
Definition: event.h:245
Implementation for a single event vector.
Definition: event.h:56
Definition: array.h:34
void set(void(tClass::*handler)(), tClass *cls) const
Set this event vector to an instance method, given a class method pointer and an instance of that cla...
Definition: event.h:188
void set(void(*handler)(void *, unsigned, unsigned, unsigned, unsigned)) const
Set this Vector to a bare function.
Definition: event.h:379
const EventVector< _SYS_CUBE_CONNECT > cubeConnect
A new cube has connected and is ready for use.
Definition: event.h:455
void unset() const
Disable this event vector.
Definition: event.h:346
Implementation for the gameMenu event vector.
Definition: event.h:220
void * handler() const
Return the currently set handler function, as a void pointer.
Definition: event.h:120
void * context() const
Return the currently set context object, as a void pointer.
Definition: event.h:407
void setLabel(const char *label) const
Set the label text used for the Game Menu item.
Definition: event.h:312
void unset() const
Disable this event vector.
Definition: event.h:66
void * handler() const
Return the currently set handler function, as a void pointer.
Definition: event.h:400
void unset() const
Disable this event vector.
Definition: event.h:155
void set(void(tClass::*handler)(unsigned), tClass *cls) const
Set this event vector to an instance method, given a class method pointer and an instance of that cla...
Definition: event.h:108
void unset() const
Disable this event vector, and disable the game menu.
Definition: event.h:228
const EventVector< _SYS_CUBE_ACCELCHANGE > cubeAccelChange
A cube's accelerometer state has changed.
Definition: event.h:475
const EventVector< _SYS_CUBE_REFRESH > cubeRefresh
The application is responsible for repainting the screen on this cube and checking its installed asse...
Definition: event.h:495