syslog_daemon: Style cleanups, no functional change.
This commit is contained in:
parent
035e3e77ed
commit
e489a80da0
@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SyslogDaemon.h"
|
#include "SyslogDaemon.h"
|
||||||
#include "listener_output.h"
|
|
||||||
#include "syslog_output.h"
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
@ -15,17 +16,20 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include "listener_output.h"
|
||||||
#include <string.h>
|
#include "syslog_output.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "SyslogDaemon"
|
#define B_TRANSLATION_CONTEXT "SyslogDaemon"
|
||||||
|
|
||||||
const char *kSignature = "application/x-vnd.Haiku-SystemLogger";
|
|
||||||
|
const char* kSignature = "application/x-vnd.Haiku-SystemLogger";
|
||||||
|
|
||||||
|
|
||||||
SyslogDaemon::SyslogDaemon()
|
SyslogDaemon::SyslogDaemon()
|
||||||
: BApplication(kSignature),
|
:
|
||||||
|
BApplication(kSignature),
|
||||||
fHandlerLock("handler lock")
|
fHandlerLock("handler lock")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -62,15 +66,16 @@ SyslogDaemon::AboutRequested()
|
|||||||
"at \"%s\".\n\n"), name.String(), path.Path());
|
"at \"%s\".\n\n"), name.String(), path.Path());
|
||||||
message.UnlockBuffer();
|
message.UnlockBuffer();
|
||||||
|
|
||||||
BAlert *alert = new BAlert(name.String(), message.String(), B_TRANSLATE("OK"));
|
BAlert* alert = new BAlert(name.String(), message.String(),
|
||||||
BTextView *view = alert->TextView();
|
B_TRANSLATE("OK"));
|
||||||
|
BTextView* view = alert->TextView();
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
view->SetStylable(true);
|
view->SetStylable(true);
|
||||||
|
|
||||||
view->GetFont(&font);
|
view->GetFont(&font);
|
||||||
font.SetSize(21);
|
font.SetSize(21);
|
||||||
font.SetFace(B_BOLD_FACE);
|
font.SetFace(B_BOLD_FACE);
|
||||||
view->SetFontAndColor(0, name.Length(), &font);
|
view->SetFontAndColor(0, name.Length(), &font);
|
||||||
|
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
@ -91,26 +96,26 @@ SyslogDaemon::QuitRequested()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SyslogDaemon::MessageReceived(BMessage *msg)
|
SyslogDaemon::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (message->what) {
|
||||||
case SYSLOG_ADD_LISTENER:
|
case SYSLOG_ADD_LISTENER:
|
||||||
{
|
{
|
||||||
BMessenger messenger;
|
BMessenger messenger;
|
||||||
if (msg->FindMessenger("target", &messenger) == B_OK)
|
if (message->FindMessenger("target", &messenger) == B_OK)
|
||||||
add_listener(&messenger);
|
add_listener(&messenger);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYSLOG_REMOVE_LISTENER:
|
case SYSLOG_REMOVE_LISTENER:
|
||||||
{
|
{
|
||||||
BMessenger messenger;
|
BMessenger messenger;
|
||||||
if (msg->FindMessenger("target", &messenger) == B_OK)
|
if (message->FindMessenger("target", &messenger) == B_OK)
|
||||||
remove_listener(&messenger);
|
remove_listener(&messenger);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(msg);
|
BApplication::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +123,7 @@ SyslogDaemon::MessageReceived(BMessage *msg)
|
|||||||
void
|
void
|
||||||
SyslogDaemon::AddHandler(handler_func function)
|
SyslogDaemon::AddHandler(handler_func function)
|
||||||
{
|
{
|
||||||
fHandlers.AddItem((void *)function);
|
fHandlers.AddItem((void*)function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,7 +131,7 @@ void
|
|||||||
SyslogDaemon::Daemon()
|
SyslogDaemon::Daemon()
|
||||||
{
|
{
|
||||||
char buffer[SYSLOG_MESSAGE_BUFFER_SIZE + 1];
|
char buffer[SYSLOG_MESSAGE_BUFFER_SIZE + 1];
|
||||||
syslog_message &message = *(syslog_message *)buffer;
|
syslog_message& message = *(syslog_message*)buffer;
|
||||||
int32 code;
|
int32 code;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -137,7 +142,8 @@ SyslogDaemon::Daemon()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we don't get what we want, ignore it
|
// 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;
|
continue;
|
||||||
|
|
||||||
// add terminating null byte
|
// add terminating null byte
|
||||||
@ -162,15 +168,15 @@ SyslogDaemon::Daemon()
|
|||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
SyslogDaemon::daemon_thread(void *data)
|
SyslogDaemon::daemon_thread(void* data)
|
||||||
{
|
{
|
||||||
((SyslogDaemon *)data)->Daemon();
|
((SyslogDaemon*)data)->Daemon();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
SyslogDaemon daemon;
|
SyslogDaemon daemon;
|
||||||
daemon.Run();
|
daemon.Run();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, 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 OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _SYSLOG_DAEMON_H_
|
#ifndef _SYSLOG_DAEMON_H_
|
||||||
#define _SYSLOG_DAEMON_H_
|
#define _SYSLOG_DAEMON_H_
|
||||||
|
|
||||||
@ -14,29 +14,30 @@
|
|||||||
#include <syslog_daemon.h>
|
#include <syslog_daemon.h>
|
||||||
|
|
||||||
|
|
||||||
typedef void (*handler_func)(syslog_message &);
|
typedef void (*handler_func)(syslog_message&);
|
||||||
|
|
||||||
|
|
||||||
class SyslogDaemon : public BApplication {
|
class SyslogDaemon : public BApplication {
|
||||||
public:
|
public:
|
||||||
SyslogDaemon();
|
SyslogDaemon();
|
||||||
|
|
||||||
virtual void ReadyToRun();
|
virtual void ReadyToRun();
|
||||||
virtual void AboutRequested();
|
virtual void AboutRequested();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
void AddHandler(handler_func function);
|
void AddHandler(handler_func function);
|
||||||
|
|
||||||
void Daemon();
|
void Daemon();
|
||||||
static int32 daemon_thread(void *data);
|
static int32 daemon_thread(void* data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
thread_id fDaemon;
|
thread_id fDaemon;
|
||||||
port_id fPort;
|
port_id fPort;
|
||||||
|
|
||||||
BLocker fHandlerLock;
|
BLocker fHandlerLock;
|
||||||
BList fHandlers;
|
BList fHandlers;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* _SYSLOG_DAEMON_H_ */
|
#endif /* _SYSLOG_DAEMON_H_ */
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, 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 OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "listener_output.h"
|
#include "listener_output.h"
|
||||||
@ -14,7 +14,7 @@ static BList sListeners;
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
listener_output(syslog_message &message)
|
listener_output(syslog_message& message)
|
||||||
{
|
{
|
||||||
// compose the message to be sent to all listeners; just convert
|
// compose the message to be sent to all listeners; just convert
|
||||||
// the syslog_message into a BMessage
|
// the syslog_message into a BMessage
|
||||||
@ -30,7 +30,7 @@ listener_output(syslog_message &message)
|
|||||||
sLocker.Lock();
|
sLocker.Lock();
|
||||||
|
|
||||||
for (int32 i = sListeners.CountItems(); i-- > 0;) {
|
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);
|
status_t status = target->SendMessage(&output);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
@ -43,8 +43,8 @@ listener_output(syslog_message &message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
remove_listener(BMessenger *messenger)
|
remove_listener(BMessenger* messenger)
|
||||||
{
|
{
|
||||||
if (sLocker.Lock()) {
|
if (sLocker.Lock()) {
|
||||||
sListeners.RemoveItem(messenger);
|
sListeners.RemoveItem(messenger);
|
||||||
@ -54,8 +54,8 @@ remove_listener(BMessenger *messenger)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
add_listener(BMessenger *messenger)
|
add_listener(BMessenger* messenger)
|
||||||
{
|
{
|
||||||
if (sLocker.Lock()) {
|
if (sLocker.Lock()) {
|
||||||
sListeners.AddItem(messenger);
|
sListeners.AddItem(messenger);
|
||||||
@ -66,7 +66,7 @@ add_listener(BMessenger *messenger)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_listener_output(SyslogDaemon *daemon)
|
init_listener_output(SyslogDaemon* daemon)
|
||||||
{
|
{
|
||||||
daemon->AddHandler(listener_output);
|
daemon->AddHandler(listener_output);
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2003, 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 OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _LISTENER_OUTPUT_H_
|
#ifndef _LISTENER_OUTPUT_H_
|
||||||
#define _LISTENER_OUTPUT_H_
|
#define _LISTENER_OUTPUT_H_
|
||||||
|
|
||||||
|
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
|
||||||
#include "SyslogDaemon.h"
|
#include "SyslogDaemon.h"
|
||||||
|
|
||||||
|
|
||||||
void init_listener_output(SyslogDaemon *daemon);
|
void init_listener_output(SyslogDaemon* daemon);
|
||||||
void add_listener(BMessenger *messenger);
|
void add_listener(BMessenger* messenger);
|
||||||
void remove_listener(BMessenger *messenger);
|
void remove_listener(BMessenger* messenger);
|
||||||
|
|
||||||
#endif /* _SYSLOG_OUTPUT_H_ */
|
|
||||||
|
#endif /* _LISTENER_OUTPUT_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user