Custom Event Management

Overview

Event Manager is a C/C++ class that assists in triggering, listening for, and responding to various events.
These events may include a room being created, a participant being added, a participant being moved, etc..
Event manager is an abstract C++ class that can be implemented and used for your specific event messaging system.
If your application uses Websockets, you can utilize our premade implementation.

Custom Event Manager

The base imm_event_manager class is a template that can be implemented to fit into any system or application.
To create a event manager to work with your specific system, simply inherit imm-event-manager and implement all
the virtual functions. When implementing each function, you should answer the question "what do I want do I want to happen
when one of these events is triggered?". For example, if your system uses Websockets, you might have your event manager
broadcast a message to all connected clients upon one of these events occuring.

Here we will provide an example of a custom manager. It doesn't do anything useful but does illustrate how to implement your own.
In this example, the custom event manager will fill a vector with events when they occur. Note that if your program is threaded,
you will want to provide thread safety to any custom class members that get written to

class custom_event_manager : public imm_event_manager {
	public:
		custom_event_manager() {
			events = new std::vector<imm_event_type>;
		}
		virtual ~custom_event_manager() {
			delete(events);
		}
		virtual void create_room_event(int room_id) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_CREATE_ROOM);
			_vector_mutex.unlock();
		}
		virtual void destroy_room_event(int room_id) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_DESTROY_ROOM);
			_vector_mutex.unlock();
		}
		virtual void add_participant_event(int room_id, int participant_id, const char* participant_name, imm_participant_configuration config) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_ADD_PARTICIPANT);
			_vector_mutex.unlock();
		}
		virtual void remove_participant_event(int room_id, int participant_id) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_REMOVE_PARTICIPANT);
			_vector_mutex.unlock();
		}
		virtual void set_participant_seat_event(int room_id, int participant_id, imm_seat seat) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_SET_PARTICIPANT_SEAT);
			_vector_mutex.unlock();
		}
		virtual void set_participant_position_event(int room_id, int participant_id, imm_position position, imm_heading heading) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_SET_PARTICIPANT_POSITION);
			_vector_mutex.unlock();
		}
		virtual void set_participant_state_event(int room_id, int participant_id, imm_audio_control control_to_edit, int value) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_SET_PARTICIPANT_STATE);
			_vector_mutex.unlock();
		}
		virtual void set_all_participants_state_event(int room_id, imm_audio_control control_to_edit, int value) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_SET_ALL_PARTICIPANTS_STATE);
			_vector_mutex.unlock();
		}
		virtual void set_room_layout_event(int room_id, int room_layout_id) {
			_vector_mutex.lock();
			events->push_back(IMM_EVENT_SET_ROOM_LAYOUT);
			_vector_mutex.unlock();
		}
		std::vector<imm_event_type>* events;
	private:
		std::mutex _vector_mutex;
};

Once you've implemented your custom logger, all you have to do to use it is instantitate an instance and add to the Immersitech Library as follows:

custom_event_manager* my_event_manager = new custom_event_manager();
imm_add_event_manager( handle, my_event_manager);

Note also that you must free the memory for your own event manager, the Immersitech Library will NOT free the memory for you.

delete( my_event_manager );

Visit imm-event-manager to see the full details of the class you must inherit.

If you are using Websockets for your event messaging system, you are in luck! We have already implemented the imm-event-manager class
to work with Websockets. Learn how use our Websocket implementation in Websocket API