midi_server: cleanup.

* Style cleanup.
* Moved documentation to source file.
* Improved variable/member naming, added '_' prefix for private methods.
This commit is contained in:
Axel Dörfler
2015-10-14 22:23:28 +02:00
parent 8a3ae7a49d
commit 83f803c6ff
2 changed files with 423 additions and 399 deletions
File diff suppressed because it is too large Load Diff
+58 -95
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009, Haiku, Inc. All rights reserved. * Copyright 2002-2015, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -8,129 +8,92 @@
#ifndef MIDI_SERVER_APP_H #ifndef MIDI_SERVER_APP_H
#define MIDI_SERVER_APP_H #define MIDI_SERVER_APP_H
#include <Application.h> #include <Application.h>
#include <List.h> #include <List.h>
#include "DeviceWatcher.h" #include "DeviceWatcher.h"
struct app_t; struct app_t;
struct endpoint_t; struct endpoint_t;
// The heart of the midi_server. This BApplication subclass
// keeps the roster of endpoints and applications, processes /*! The heart of the midi_server. This BApplication subclass
// incoming messages from libmidi2.so, and notifies the apps keeps the roster of endpoints and applications, processes
// when something interesting happens. incoming messages from libmidi2.so, and notifies the apps
class MidiServerApp : public BApplication when something interesting happens.
{ */
class MidiServerApp : public BApplication {
public: public:
MidiServerApp();
virtual ~MidiServerApp();
MidiServerApp(); virtual void AboutRequested();
virtual ~MidiServerApp(); virtual void MessageReceived(BMessage* msg);
virtual void AboutRequested();
virtual void MessageReceived(BMessage* msg);
private: private:
typedef BApplication super; typedef BApplication super;
void OnRegisterApp(BMessage* msg); void _OnRegisterApp(BMessage* msg);
void OnCreateEndpoint(BMessage* msg); void _OnCreateEndpoint(BMessage* msg);
void OnDeleteEndpoint(BMessage* msg); void _OnDeleteEndpoint(BMessage* msg);
void OnPurgeEndpoint(BMessage* msg); void _OnPurgeEndpoint(BMessage* msg);
void OnChangeEndpoint(BMessage* msg); void _OnChangeEndpoint(BMessage* msg);
void OnConnectDisconnect(BMessage* msg); void _OnConnectDisconnect(BMessage* msg);
// Sends an app MSG_ENDPOINT_CREATED notifications for bool _SendAllEndpoints(app_t* app);
// all current endpoints. Used when the app registers. bool _SendAllConnections(app_t* app);
bool SendAllEndpoints(app_t* app);
// Sends an app MSG_ENDPOINTS_CONNECTED notifications for void _AddEndpoint(BMessage* msg, endpoint_t* endp);
// all current connections. Used when the app registers. void _RemoveEndpoint(app_t* app, endpoint_t* endp);
bool SendAllConnections(app_t* app);
// Adds the specified endpoint to the roster, and notifies void _DisconnectDeadConsumer(endpoint_t* cons);
// all other applications about this event.
void AddEndpoint(BMessage* msg, endpoint_t* endp);
// Removes an endpoint from the roster, and notifies all void _MakeCreatedNotification(BMessage* msg,
// other apps about this event. "app" is the application endpoint_t* endp);
// that the endpoint belongs to; if it is NULL, the app void _MakeConnectedNotification(BMessage* msg,
// no longer exists and we're purging the endpoint. endpoint_t* prod, endpoint_t* cons,
void RemoveEndpoint(app_t* app, endpoint_t* endp); bool mustConnect);
// Removes a consumer from the list of connections of app_t* _WhichApp(BMessage* msg);
// all the producers it is connected to, just before endpoint_t* _WhichEndpoint(BMessage* msg, app_t* app);
// we remove it from the roster. endpoint_t* _FindEndpoint(int32 id);
void DisconnectDeadConsumer(endpoint_t* cons);
// Fills up a MSG_ENDPOINT_CREATED message. void _NotifyAll(BMessage* msg, app_t* except);
void MakeCreatedNotification(BMessage* msg, endpoint_t* endp); bool _SendNotification(app_t* app, BMessage* msg);
bool _SendReply(app_t* app, BMessage* msg,
BMessage* reply);
// Fills up a MSG_ENDPOINTS_(DIS)CONNECTED message. void _DeliveryError(app_t* app);
void MakeConnectedNotification(
BMessage* msg, endpoint_t* prod, endpoint_t* cons, bool mustConnect);
// Figures out which application a message came from. int32 _CountApps();
// Returns NULL if the application is not registered. app_t* _AppAt(int32 index);
app_t* WhichApp(BMessage* msg);
// Looks at the "midi:id" field from a message, and returns int32 _CountEndpoints();
// the endpoint object that corresponds to that ID. It also endpoint_t* _EndpointAt(int32 index);
// checks whether the application specified by "app" really
// owns the endpoint. Returns NULL on error.
endpoint_t* WhichEndpoint(BMessage* msg, app_t* app);
// Returns the endpoint with the specified ID, or int32 _CountConnections(endpoint_t* prod);
// NULL if no such endpoint exists on the roster. endpoint_t* _ConnectionAt(endpoint_t* prod, int32 index);
endpoint_t* FindEndpoint(int32 id);
// Sends notification messages to all registered apps, #ifdef DEBUG
// except to the application that triggered the event. void _DumpApps();
// The "except" app is allowed to be NULL. void _DumpEndpoints();
void NotifyAll(BMessage* msg, app_t* except); #endif
// Sends a notification message to an application, which is private:
// not necessarily registered yet. Applications never reply //! The registered applications.
// to such notification messages. BList fApps;
bool SendNotification(app_t* app, BMessage* msg);
// Sends a reply to a request made by an application. //! All the endpoints in the system.
// If "app" is NULL, the application is not registered BList fEndpoints;
// (and the reply should contain an error code).
bool SendReply(app_t* app, BMessage* msg, BMessage* reply);
// Removes an app and all of its endpoints from the roster //! The ID we will assign to the next new endpoint.
// if a reply or notification message cannot be delivered. int32 fNextID;
// (Waiting for communications to fail is actually our only
// way to get rid of stale endpoints.)
void DeliveryError(app_t* app);
int32 CountApps(); //! Watch endpoints from /dev/midi drivers.
app_t* AppAt(int32 index); DeviceWatcher* fDeviceWatcher;
int32 CountEndpoints();
endpoint_t* EndpointAt(int32 index);
int32 CountConnections(endpoint_t* prod);
endpoint_t* ConnectionAt(endpoint_t* prod, int32 index);
// The registered applications.
BList apps;
// All the endpoints in the system.
BList endpoints;
// The ID we will assign to the next new endpoint.
int32 nextId;
// Watch endpoints from /dev/midi drivers.
DeviceWatcher* fDeviceWatcher;
#ifdef DEBUG
void DumpApps();
void DumpEndpoints();
#endif
}; };
#endif // MIDI_SERVER_APP_H #endif // MIDI_SERVER_APP_H