syslog_daemon: Style cleanups, no functional change.

This commit is contained in:
Axel Dörfler 2015-04-15 17:32:12 +02:00
parent 035e3e77ed
commit e489a80da0
4 changed files with 69 additions and 59 deletions

View File

@ -1,12 +1,13 @@
/*
* Copyright 2003-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
* Copyright 2003-2015, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include "SyslogDaemon.h"
#include "listener_output.h"
#include "syslog_output.h"
#include <stdio.h>
#include <string.h>
#include <Alert.h>
#include <Catalog.h>
@ -15,17 +16,20 @@
#include <Path.h>
#include <TextView.h>
#include <stdio.h>
#include <string.h>
#include "listener_output.h"
#include "syslog_output.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "SyslogDaemon"
const char *kSignature = "application/x-vnd.Haiku-SystemLogger";
const char* kSignature = "application/x-vnd.Haiku-SystemLogger";
SyslogDaemon::SyslogDaemon()
: BApplication(kSignature),
:
BApplication(kSignature),
fHandlerLock("handler lock")
{
}
@ -62,15 +66,16 @@ SyslogDaemon::AboutRequested()
"at \"%s\".\n\n"), name.String(), path.Path());
message.UnlockBuffer();
BAlert *alert = new BAlert(name.String(), message.String(), B_TRANSLATE("OK"));
BTextView *view = alert->TextView();
BAlert* alert = new BAlert(name.String(), message.String(),
B_TRANSLATE("OK"));
BTextView* view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetSize(21);
font.SetFace(B_BOLD_FACE);
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, name.Length(), &font);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
@ -91,26 +96,26 @@ SyslogDaemon::QuitRequested()
void
SyslogDaemon::MessageReceived(BMessage *msg)
SyslogDaemon::MessageReceived(BMessage* message)
{
switch (msg->what) {
switch (message->what) {
case SYSLOG_ADD_LISTENER:
{
BMessenger messenger;
if (msg->FindMessenger("target", &messenger) == B_OK)
if (message->FindMessenger("target", &messenger) == B_OK)
add_listener(&messenger);
break;
}
case SYSLOG_REMOVE_LISTENER:
{
BMessenger messenger;
if (msg->FindMessenger("target", &messenger) == B_OK)
if (message->FindMessenger("target", &messenger) == B_OK)
remove_listener(&messenger);
break;
}
default:
BApplication::MessageReceived(msg);
BApplication::MessageReceived(message);
}
}
@ -118,7 +123,7 @@ SyslogDaemon::MessageReceived(BMessage *msg)
void
SyslogDaemon::AddHandler(handler_func function)
{
fHandlers.AddItem((void *)function);
fHandlers.AddItem((void*)function);
}
@ -126,7 +131,7 @@ void
SyslogDaemon::Daemon()
{
char buffer[SYSLOG_MESSAGE_BUFFER_SIZE + 1];
syslog_message &message = *(syslog_message *)buffer;
syslog_message& message = *(syslog_message*)buffer;
int32 code;
while (true) {
@ -137,7 +142,8 @@ SyslogDaemon::Daemon()
}
// if we don't get what we want, ignore it
if (bytesRead < (ssize_t)sizeof(syslog_message) || code != SYSLOG_MESSAGE)
if (bytesRead < (ssize_t)sizeof(syslog_message)
|| code != SYSLOG_MESSAGE)
continue;
// add terminating null byte
@ -162,15 +168,15 @@ SyslogDaemon::Daemon()
int32
SyslogDaemon::daemon_thread(void *data)
SyslogDaemon::daemon_thread(void* data)
{
((SyslogDaemon *)data)->Daemon();
((SyslogDaemon*)data)->Daemon();
return B_OK;
}
int
main(int argc, char **argv)
main(int argc, char** argv)
{
SyslogDaemon daemon;
daemon.Run();

View File

@ -1,7 +1,7 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
/*
* Copyright 2003-2015, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _SYSLOG_DAEMON_H_
#define _SYSLOG_DAEMON_H_
@ -14,29 +14,30 @@
#include <syslog_daemon.h>
typedef void (*handler_func)(syslog_message &);
typedef void (*handler_func)(syslog_message&);
class SyslogDaemon : public BApplication {
public:
SyslogDaemon();
public:
SyslogDaemon();
virtual void ReadyToRun();
virtual void AboutRequested();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *msg);
virtual void ReadyToRun();
virtual void AboutRequested();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message);
void AddHandler(handler_func function);
void AddHandler(handler_func function);
void Daemon();
static int32 daemon_thread(void *data);
void Daemon();
static int32 daemon_thread(void* data);
private:
thread_id fDaemon;
port_id fPort;
private:
thread_id fDaemon;
port_id fPort;
BLocker fHandlerLock;
BList fHandlers;
BLocker fHandlerLock;
BList fHandlers;
};
#endif /* _SYSLOG_DAEMON_H_ */

View File

@ -1,7 +1,7 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
/*
* Copyright 2003-2015, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#include "listener_output.h"
@ -14,7 +14,7 @@ static BList sListeners;
static void
listener_output(syslog_message &message)
listener_output(syslog_message& message)
{
// compose the message to be sent to all listeners; just convert
// the syslog_message into a BMessage
@ -30,7 +30,7 @@ listener_output(syslog_message &message)
sLocker.Lock();
for (int32 i = sListeners.CountItems(); i-- > 0;) {
BMessenger *target = (BMessenger *)sListeners.ItemAt(i);
BMessenger* target = (BMessenger*)sListeners.ItemAt(i);
status_t status = target->SendMessage(&output);
if (status < B_OK) {
@ -43,8 +43,8 @@ listener_output(syslog_message &message)
}
void
remove_listener(BMessenger *messenger)
void
remove_listener(BMessenger* messenger)
{
if (sLocker.Lock()) {
sListeners.RemoveItem(messenger);
@ -54,8 +54,8 @@ remove_listener(BMessenger *messenger)
}
void
add_listener(BMessenger *messenger)
void
add_listener(BMessenger* messenger)
{
if (sLocker.Lock()) {
sListeners.AddItem(messenger);
@ -66,7 +66,7 @@ add_listener(BMessenger *messenger)
void
init_listener_output(SyslogDaemon *daemon)
init_listener_output(SyslogDaemon* daemon)
{
daemon->AddHandler(listener_output);
}

View File

@ -1,16 +1,19 @@
/*
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
/*
* Copyright 2003-2015, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _LISTENER_OUTPUT_H_
#define _LISTENER_OUTPUT_H_
#include <Messenger.h>
#include "SyslogDaemon.h"
void init_listener_output(SyslogDaemon *daemon);
void add_listener(BMessenger *messenger);
void remove_listener(BMessenger *messenger);
void init_listener_output(SyslogDaemon* daemon);
void add_listener(BMessenger* messenger);
void remove_listener(BMessenger* messenger);
#endif /* _SYSLOG_OUTPUT_H_ */
#endif /* _LISTENER_OUTPUT_H_ */