1 /* 2 * Copyright 2002-2015, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Matthijs Hollemans 7 */ 8 #ifndef MIDI_SERVER_APP_H 9 #define MIDI_SERVER_APP_H 10 11 12 #include <Server.h> 13 #include <List.h> 14 15 #include "DeviceWatcher.h" 16 17 18 struct app_t; 19 struct endpoint_t; 20 21 22 /*! The heart of the midi_server. This BApplication subclass 23 keeps the roster of endpoints and applications, processes 24 incoming messages from libmidi2.so, and notifies the apps 25 when something interesting happens. 26 */ 27 class MidiServerApp : public BServer { 28 public: 29 MidiServerApp(status_t& error); 30 virtual ~MidiServerApp(); 31 32 virtual void AboutRequested(); 33 virtual void MessageReceived(BMessage* msg); 34 35 private: 36 typedef BServer super; 37 38 void _OnRegisterApp(BMessage* msg); 39 void _OnCreateEndpoint(BMessage* msg); 40 void _OnDeleteEndpoint(BMessage* msg); 41 void _OnPurgeEndpoint(BMessage* msg); 42 void _OnChangeEndpoint(BMessage* msg); 43 void _OnConnectDisconnect(BMessage* msg); 44 45 bool _SendAllEndpoints(app_t* app); 46 bool _SendAllConnections(app_t* app); 47 48 void _AddEndpoint(BMessage* msg, endpoint_t* endp); 49 void _RemoveEndpoint(app_t* app, endpoint_t* endp); 50 51 void _DisconnectDeadConsumer(endpoint_t* cons); 52 53 void _MakeCreatedNotification(BMessage* msg, 54 endpoint_t* endp); 55 void _MakeConnectedNotification(BMessage* msg, 56 endpoint_t* prod, endpoint_t* cons, 57 bool mustConnect); 58 59 app_t* _WhichApp(BMessage* msg); 60 endpoint_t* _WhichEndpoint(BMessage* msg, app_t* app); 61 endpoint_t* _FindEndpoint(int32 id); 62 63 void _NotifyAll(BMessage* msg, app_t* except); 64 bool _SendNotification(app_t* app, BMessage* msg); 65 bool _SendReply(app_t* app, BMessage* msg, 66 BMessage* reply); 67 68 void _DeliveryError(app_t* app); 69 70 int32 _CountApps(); 71 app_t* _AppAt(int32 index); 72 73 int32 _CountEndpoints(); 74 endpoint_t* _EndpointAt(int32 index); 75 76 int32 _CountConnections(endpoint_t* prod); 77 endpoint_t* _ConnectionAt(endpoint_t* prod, int32 index); 78 79 #ifdef DEBUG 80 void _DumpApps(); 81 void _DumpEndpoints(); 82 #endif 83 84 private: 85 //! The registered applications. 86 BList fApps; 87 88 //! All the endpoints in the system. 89 BList fEndpoints; 90 91 //! The ID we will assign to the next new endpoint. 92 int32 fNextID; 93 94 //! Watch endpoints from /dev/midi drivers. 95 DeviceWatcher* fDeviceWatcher; 96 }; 97 98 99 #endif // MIDI_SERVER_APP_H 100