summaryrefslogtreecommitdiff
path: root/examples/NT_Service/ntsvc.h
blob: 2d74beab53b75a4c8b4e66f66b9481ecf81bc880 (plain)
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
// $Id$

// ============================================================================
//
// = LIBRARY
//    examples/NT_Service
//
// = FILENAME
//    ntsvc.h
//
// = DESCRIPTION
//      This is the definition of the sample NT Service class.
//
// = AUTHOR
//    Gonzalo Diethelm and Steve Huston
//
// ============================================================================

#ifndef NTSVC_H_
#define NTSVC_H_

#include "ace/Event_Handler.h"
#include "ace/NT_Service.h"
#include "ace/Singleton.h"
#include "ace/Synch.h"

class Service : public ACE_NT_Service
{
public:
  Service();

  // We override handle_control() because it handles stop requests privately.
  virtual void handle_control(DWORD control_code);

  // We override handle_exception() so a 'stop' control code can pop
  // the reactor off of its wait.
  virtual int  handle_exception(ACE_HANDLE h);

  // This is a virtual method inherited from ACE_NT_Service.
  virtual int svc();

  // Where the real work is done:
  virtual int handle_timeout(const ACE_Time_Value& tv,
                             const void* arg = 0);

private:
  typedef ACE_NT_Service inherited;

private:
  int stop_;
};


// Define a singleton class as a way to insure that there's only one
// Service instance in the program, and to protect against access from
// multiple threads.  The first reference to it at runtime creates it,
// and the ACE_Object_Manager deletes it at run-down.
typedef ACE_Singleton<Service, ACE_Mutex> SERVICE;

#endif /* #ifndef NTSVC_H_ */