File: LogServer.cpp

package info (click to toggle)
libassa 3.5.1-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,424 kB
  • sloc: cpp: 15,703; sh: 12,083; makefile: 379; perl: 51
file content (107 lines) | stat: -rw-r--r-- 2,874 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// -*- c++ -*-
// Generated by assa-genesis
//------------------------------------------------------------------------------
// $Id: LogServer.cpp,v 1.7 2006/07/20 02:30:55 vlg Exp $
//------------------------------------------------------------------------------
//                            LogServer.cpp
//------------------------------------------------------------------------------
//  Copyright (c) 2003 by Vladislav Grinchenko
//
//  This program is free software; you can redistribute it and/or 
//  modify it under the terms of the GNU General Public License   
//  as published by the Free Software Foundation; either version  
//  2 of the License, or (at your option) any later version.      
//------------------------------------------------------------------------------
//
// Date   : Thu Apr 17 17:31:20 2003
//
//------------------------------------------------------------------------------

#include <assa/INETAddress.h>

#include "LogServer-main.h"
using ASSA::ASSAERR;

#include "LogServer.h"
#include "Conn.h"
#include "MonitorConn.h"


// Static declarations mandated by Singleton class
ASSA_DECL_SINGLETON(LogServer);

LogServer::
LogServer () : 
	m_acceptor (NULL),
	m_monitor_acceptor (NULL),
	m_recycle (false)
{
	rm_opt ('c', "log-level");
	rm_opt ('s', "with-log-server");
	rm_opt ('S', "log-server");

	if (!add_opt (0, "log-dir", &m_log_dir)) {
		std::cerr << "Error : \"" << get_opt_error () << "\"\n";
		exit (1);
	}
	add_flag_opt (0, "recycle", &m_recycle);

	add_opt (0, "monitor-port", &m_monitor_port);

    /*---
     * By defauil disable all debugging
     *---*/
    m_mask = ASSA::APP | ASSA::ASSAERR;
    m_log_file = "assa-logd.log";
}

void
LogServer::
init_service ()
{
    trace("LogServer::init_service");

	std::string aport (get_port ());

	if (aport.length () == 0) {
		aport = "assalogd@localhost";
	}

	if (m_monitor_port.length () == 0) {
		m_monitor_port = "assalmon@localhost";
	}

	m_acceptor = new ASSA::Acceptor<Conn, ASSA::IPv4Socket> (get_reactor ());
	m_acceptor->set_id ("AppPort");

	ASSA::INETAddress lport (aport.c_str ());
	Assure_exit (!lport.bad ());
	Assure_exit (m_acceptor->open (lport) == 0);

	m_monitor_acceptor = 
		new ASSA::Acceptor<MonitorConn, ASSA::IPv4Socket> (get_reactor ());
	m_monitor_acceptor->set_id ("LogMonPort");
	
	ASSA::INETAddress lmport (m_monitor_port.c_str ());
	Assure_exit (!lmport.bad ());
	Assure_exit (m_monitor_acceptor->open (lmport) == 0);
	
    DL((ASSA::APP,"Service has been initialized\n"));
}

void
LogServer::
process_events ()
{
    trace("LogServer::process_events");

    while (service_is_active ()) {
        m_reactor.waitForEvents ();
    }

    // Shut the service down
    m_reactor.stopReactor ();
    DL((ASSA::APP,"Service stopped!\n"));
}