---
title: llarp/util/service_manager.hpp

---

# llarp/util/service_manager.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::sys](Namespaces/namespacellarp_1_1sys.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| class | **[llarp::sys::I_SystemLayerManager](Classes/classllarp_1_1sys_1_1I__SystemLayerManager.md)** <br>interface type for interacting with the os dependant system layer  |
| class | **[llarp::sys::NOP_SystemLayerHandler](Classes/classllarp_1_1sys_1_1NOP__SystemLayerHandler.md)**  |




## Source code

```cpp
#pragma once

namespace llarp
{
  struct Context;
}

namespace llarp::sys
{

  // what state lokinet will report we are in to the system layer
  enum class ServiceState
  {
    Initial,
    Starting,
    Running,
    Stopping,
    Stopped,
    HardStop,
    Failed,
  };

  class I_SystemLayerManager
  {
   protected:
    bool m_disable{false};
    llarp::Context* m_Context{nullptr};

    virtual void
    we_changed_our_state(ServiceState st) = 0;

   public:
    virtual ~I_SystemLayerManager() = default;

    inline void
    disable()
    {
      m_disable = true;
    }

    inline void
    give_context(llarp::Context* ctx)
    {
      m_Context = ctx;
    }

    virtual void
    system_changed_our_state(ServiceState st) = 0;

    virtual void
    report_changed_state() = 0;

    virtual void
    report_periodic_stats(){};

    void
    starting()
    {
      if (m_disable)
        return;
      we_changed_our_state(ServiceState::Starting);
    }

    void
    ready()
    {
      if (m_disable)
        return;
      we_changed_our_state(ServiceState::Running);
    }

    void
    stopping()
    {
      if (m_disable)
        return;
      we_changed_our_state(ServiceState::Stopping);
    }

    void
    stopped()
    {
      if (m_disable)
        return;
      we_changed_our_state(ServiceState::Stopped);
    }

    void
    failed()
    {
      if (m_disable)
        return;
      we_changed_our_state(ServiceState::Failed);
    }
  };

  extern I_SystemLayerManager* const service_manager;

  class NOP_SystemLayerHandler : public I_SystemLayerManager
  {
   protected:
    void
    we_changed_our_state(ServiceState) override
    {}

   public:
    void
    report_changed_state() override{};
    void system_changed_our_state(ServiceState) override{};
  };
}  // namespace llarp::sys
```


-------------------------------

Updated on 2022-11-17 at 22:27:42 +0000
