Program Listing for File ecal_process.h

Return to documentation for file (ecal/core/include/ecal/ecal_process.h)

/* ========================= eCAL LICENSE =================================
 *
 * Copyright (C) 2016 - 2019 Continental Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * ========================= eCAL LICENSE =================================
*/

#pragma once

#include <string>

#include <ecal/ecal_os.h>
#include <ecal/ecal_process_mode.h>
#include <ecal/ecal_process_severity.h>
#include <ecal/ecal_callback.h>

namespace eCAL
{
  namespace Process
  {
    ECAL_API void DumpConfig();

    ECAL_API void DumpConfig(std::string& cfg_s_);

    ECAL_API std::string GetHostName();

    ECAL_API int GetHostID();

    ECAL_API std::string GetUnitName();

    ECAL_API std::string GetTaskParameter(const char* sep_);

    ECAL_API void SleepMS(long time_ms_);

    ECAL_API int GetProcessID();

    ECAL_API std::string GetProcessIDAsString();

    ECAL_API std::string GetProcessName();

    ECAL_API std::string GetProcessParameter();

    ECAL_API float GetProcessCpuUsage();

    ECAL_API unsigned long GetProcessMemory();

    [[deprecated("use GetWClock() instead")]]
    ECAL_API long long GetSClock();

    [[deprecated("use GetWBytes() instead")]]
    ECAL_API long long GetSBytes();

    ECAL_API long long GetWClock();

    ECAL_API long long GetWBytes();

    ECAL_API long long GetRClock();

    ECAL_API long long GetRBytes();

    ECAL_API void SetState(eCAL_Process_eSeverity severity_, eCAL_Process_eSeverity_Level level_, const char* info_);

    ECAL_API int AddRegistrationCallback(enum eCAL_Registration_Event event_, RegistrationCallbackT callback_);

    ECAL_API int RemRegistrationCallback(enum eCAL_Registration_Event event_);

    ECAL_API int StartProcess(const char* proc_name_, const char* proc_args_, const char* working_dir_, bool create_console_, eCAL_Process_eStartMode process_mode_, bool block_);

    ECAL_API bool StopProcess(const char* proc_name_);

    ECAL_API bool StopProcess(int proc_id_);
  }
}

#ifdef ECAL_C_DLL

#include <ecal/ecalc.h>

namespace eCAL
{
  namespace Process
  {
    inline void DumpConfig()
    {
      eCAL_Process_DumpConfig();
    }

    inline std::string GetHostName()
    {
      void* buf = nullptr;
      std::string name;
      size_t buf_len = eCAL_Process_GetHostName(&buf, ECAL_ALLOCATE_4ME);
      if(buf_len > 0)
      {
        name = std::string(static_cast<char*>(buf), buf_len);
        eCAL_FreeMem(buf);
      }
      return(name);
    }

    inline int GetHostID()
    {
      return(eCAL_Process_GetHostID());
    }

    inline std::string GetUnitName()
    {
      void* buf = nullptr;
      std::string name;
      size_t buf_len = eCAL_Process_GetUnitName(&buf, ECAL_ALLOCATE_4ME);
      if(buf_len > 0)
      {
        name = std::string(static_cast<char*>(buf), buf_len);
        eCAL_FreeMem(buf);
      }
      return(name);
    }

    inline std::string GetTaskParameter(const char* sep_)
    {
      void* buf = nullptr;
      std::string par;
      size_t buf_len = eCAL_Process_GetTaskParameter(&buf, ECAL_ALLOCATE_4ME, sep_);
      if(buf_len > 0)
      {
        par = std::string(static_cast<char*>(buf), buf_len);
        eCAL_FreeMem(buf);
      }
      return(par);
    }

    inline void SleepMS(long time_ms_)
    {
      eCAL_Process_SleepMS(time_ms_);
    }

    inline int GetProcessID()
    {
      return(eCAL_Process_GetProcessID());
    }

    inline std::string GetProcessName()
    {
      void* buf = nullptr;
      std::string name;
      size_t buf_len = eCAL_Process_GetProcessName(&buf, ECAL_ALLOCATE_4ME);
      if(buf_len > 0)
      {
        name = std::string(static_cast<char*>(buf), buf_len);
        eCAL_FreeMem(buf);
      }
      return(name);
    }

    inline std::string GetProcessParameter()
    {
      void* buf = nullptr;
      std::string par;
      size_t buf_len = eCAL_Process_GetProcessParameter(&buf, ECAL_ALLOCATE_4ME);
      if(buf_len > 0)
      {
        par = std::string(static_cast<char*>(buf), buf_len);
        eCAL_FreeMem(buf);
      }
      return(par);
    }

    inline float GetProcessCpuUsage()
    {
      return(eCAL_Process_GetProcessCpuUsage());
    }

    inline unsigned long GetProcessMemory()
    {
      return(eCAL_Process_GetProcessMemory());
    }

    [[deprecated("use GetWClock() instead")]]
    inline long long GetSClock()
    {
      return(eCAL_Process_GetWClock());
    }

    [[deprecated("use GetWBytes() instead")]]
    inline long long GetSBytes()
    {
      return(eCAL_Process_GetWBytes());
    }

    inline long long GetWClock()
    {
      return(eCAL_Process_GetWClock());
    }

    inline long long GetWBytes()
    {
      return(eCAL_Process_GetWBytes());
    }

    inline long long GetRClock()
    {
      return(eCAL_Process_GetRClock());
    }

    inline long long GetRBytes()
    {
      return(eCAL_Process_GetRBytes());
    }

    inline void SetState(eCAL_Process_eSeverity severity_, eCAL_Process_eSeverity_Level level_, const char* info_)
    {
      eCAL_Process_SetState(severity_, level_, info_);
    }

    inline int StartProcess(const char* proc_name_, const char* proc_args_, const char* working_dir_, bool create_console_, eCAL_Process_eStartMode process_mode_, bool block_)
    {
      return(eCAL_Process_StartProcess(proc_name_, proc_args_, working_dir_, create_console_, process_mode_, block_));
    }

    inline bool StopProcess(const char* proc_name_)
    {
      return(eCAL_Process_StopProcessName(proc_name_) != 0);
    }

    inline bool StopProcess(int proc_id_)
    {
      return(eCAL_Process_StopProcessID(proc_id_) != 0);
    }
  }
}

#endif /* ECAL_C_DLL */