aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/um/service/include/libservice/service.hpp
blob: 089f79035f07bf7151340cd53cfbe919069b458e (plain) (blame)
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
// Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
// This file is part of the "Windows 7 drivers" project.
// For details, see https://github.com/egor-tensin/windows7-drivers.
// Distributed under the MIT License.

#pragma once

#include "common.hpp"
#include "service_handle.hpp"
#include "service_manager.hpp"

#include <string>
#include <utility>

namespace libservice
{
    class Service
    {
    public:
        static bool exists(
            const ServiceManager&,
            const std::string& name);

        static Service open(
            const ServiceManager&,
            const std::string& name);

        static Service install(
            const ServiceManager&,
            const std::string& name,
            const std::string& bin_path);

        void start() const;
        void stop() const;
        void uninstall() const;

        Service(Service&& other) LIBSERVICE_NOEXCEPT
        {
            swap(other);
        }

        Service& operator=(Service other) LIBSERVICE_NOEXCEPT
        {
            swap(other);
            return *this;
        }

        void swap(Service& other) LIBSERVICE_NOEXCEPT
        {
            using std::swap;
            swap(handle, other.handle);
        }

    private:
        Service(ServiceHandle handle)
            : handle(std::move(handle))
        { }

        ServiceHandle handle;

        Service(const Service&) = delete;
    };

    void swap(Service&, Service&) LIBSERVICE_NOEXCEPT;
}

namespace std
{
    template <>
    void swap<libservice::Service>(
        libservice::Service&,
        libservice::Service&) LIBSERVICE_NOEXCEPT;
}