Since you guys rock at giving advice and google isn't helping again...
Okay, halfway through my interprocess API I realise I have no idea what the best way is to convey information from thread to thread.
I have:
- Asynchronous messaging system sending "Action" objects, which will be processed by another thread. (lockfree yay)
- Using shared pointers I can send pointers around, and even use an Action to hold a return value if needed. (threadsafe yay)
I need/want:
- Some way of an "Action" message object to hold an actual parametrised action. How will the receiver know what to do?
- Speed, string parsing is out of the question
- Flexibility, should be easy to add new types of actions
Ideas so far:
- Send pre-filled function pointers (very dependent on the receiver's function structure), very flexible though
- Enum the actions and have a switch decide (less flexible, and have to pre-define parameters somehow)
- ? ? ?
Types of actions that will be sent:
- Add Object* X to the screen cache;
- Remove Object* X from the screen cache;
- Put Object* X in the Dynamic List;
- Move Object* X, 0.5 units to it's local west-direction.
- Place a new Object, location: (x,y,z), Object_Design: Ball, Object_Material:Rock_5
Any good ideas (even though reinventing the wheel is good for me
), or reasons why I shouldn't build an API using function pointers, if that's even possible?
shared_ptr<Action> a(new Action(GraphicsManager::addObject(), controller->getGraphics(), newObject*));
controller->getGraphics()->pushAction(a);