summaryrefslogtreecommitdiffstats
path: root/src/common/win32/service.h
blob: 20d37a876639ad0d4f0c0cfb1c97e6c4ba434e71 (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
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2019 SUSE LINUX GmbH
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation.  See file COPYING.
 *
 */

#include "include/compat.h"
#include "common/ceph_context.h"

class ServiceBase {

public:
  ServiceBase(CephContext *cct_);
  virtual ~ServiceBase() {};

  static int initialize(ServiceBase *service);
protected:
  static void run();
  static void control_handler(DWORD request);

  void shutdown(bool ignore_errors = false);
  void stop();

  void set_status(DWORD current_state, DWORD exit_code = NO_ERROR);

  /* Subclasses should implement the following service hooks. */
  virtual int run_hook() = 0;
  /* Invoked when the service is requested to stop. */
  virtual int stop_hook() = 0;
  /* Invoked when the system is shutting down. */
  virtual int shutdown_hook() = 0;

  CephContext *cct;

private:
  /* A handle used when reporting the current status. */
  SERVICE_STATUS_HANDLE hstatus;
  /* The current service status. */
  SERVICE_STATUS status;

  /* singleton service instance */
  static ServiceBase *s_service;
};