aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/um/service/include/libservice/service_manager.hpp
blob: 80e6f12226d4e43afa1a2318eb030f1de56ae3b4 (plain) (tree)
1
2
3
4



                                                                    






























                                                                           
                                       

         
                                  
         
                          


            

                                            

           
                             













                                                                        
// 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 <Windows.h>

#include <utility>

namespace libservice
{
    class ServiceManager
    {
    public:
        static ServiceManager open();

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

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

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

        operator SC_HANDLE() const
        {
            return handle;
        }

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

        ServiceHandle handle;

        ServiceManager(const ServiceManager&) = delete;
    };

    void swap(ServiceManager& a, ServiceManager& b) LIBSERVICE_NOEXCEPT;
}

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