File: LogMon.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 (90 lines) | stat: -rw-r--r-- 2,365 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
// -*- c++ -*-
// Generated by assa-genesis
//------------------------------------------------------------------------------
// $Id: LogMon.cpp,v 1.5 2006/07/20 02:30:55 vlg Exp $
//------------------------------------------------------------------------------
//                            LogMon.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 22:49:49 2003
//
//------------------------------------------------------------------------------

#include <assa/INETAddress.h>
#include <assa/TimeVal.h>

#include "LogMon-main.h"
#include "LogMon.h"

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

LogMon::
LogMon () : 
	m_peer (NULL)
{
    // ---Configuration---
    rm_opt ('f', "config-file"  );
    rm_opt ('n', "instance"     );

    // ---Process bookkeeping---
    rm_opt ('b', "daemon"       );
    rm_opt ('l', "pidfile"      );
	rm_opt ('L', "ommit-pidfile");
 
	m_ommit_pidfile = "yes";

    /*---
     * By defauil disable all debugging
     *---*/
    m_mask = ASSA::APP | ASSA::ASSAERR;
    m_log_file = "LogMon.log";
	
	set_port ("assalmon");	// ASSA logging server monitoring port
}

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

	m_peer = new LogConn;
	ASSA::INETAddress lmon_addr (get_port ().c_str ());

	ASSA::TimeVal timeout (5.0); 
	m_connector.open (timeout, ASSA::async, REACTOR);

	if (m_connector.connect (m_peer, lmon_addr) < 0) {
		DL((ASSA::ASSAERR,"Failed to connect to server\n"));
		stop_service ();
		return;
	}
	
    DL((ASSA::APP,"Service has been initialized\n"));
}

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

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

    // Shut the service down
    m_reactor.stopReactor ();

    DL((ASSA::APP,"Service stopped!\n"));
}