Skip to content

Commit

Permalink
system.info added
Browse files Browse the repository at this point in the history
related to #174
  • Loading branch information
uliss committed May 7, 2024
1 parent c21b3a8 commit 3fd28be
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
1 change: 1 addition & 0 deletions ceammc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- net.ws.server - WebSocket client
- route.data (with route.d alias) - separate data from other types
- system.command (with system.cmd alias) - run several processes like in shell with pipes
- system.info - object to get num cpu/temperature and other system information
- new properties:
- dict->list @props flag added to output as list of properties
- snd.play~ @on_err property added to specify sending errors address
Expand Down
12 changes: 11 additions & 1 deletion ceammc/ext/src/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,21 @@ target_link_libraries(ceammc_system PRIVATE tiny-process-library)
# command
target_sources(ceammc_system PRIVATE system_command.cpp)
if(WITH_SYSTEM_CMD)
target_sources(ceammc_system PRIVATE system_command.cpp)
target_include_directories(ceammc_system
PRIVATE
${PROJECT_SOURCE_DIR}/ceammc/extra/rust/system
)
target_link_libraries(ceammc_system PRIVATE system_rust)
target_compile_definitions(ceammc_system PRIVATE WITH_SYSTEM_CMD)
endif()

# sysinfo
target_sources(ceammc_system PRIVATE system_info.cpp)
if(WITH_SYSTEM_INFO)
target_include_directories(ceammc_system
PRIVATE
${PROJECT_SOURCE_DIR}/ceammc/extra/rust/system
)
target_link_libraries(ceammc_system PRIVATE system_rust)
target_compile_definitions(ceammc_system PRIVATE WITH_SYSTEM_INFO)
endif()
2 changes: 2 additions & 0 deletions ceammc/ext/src/system/mod_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void setup_system_exec();
void setup_system_exit();
void setup_system_getenv();
void setup_system_hostname();
void setup_system_info();
void setup_system_memsize();
void setup_system_memused();
void setup_system_screen_size();
Expand All @@ -20,6 +21,7 @@ void ceammc_system_setup()
setup_system_exit();
setup_system_getenv();
setup_system_hostname();
setup_system_info();
setup_system_memsize();
setup_system_memused();
setup_system_screen_size();
Expand Down
58 changes: 58 additions & 0 deletions ceammc/ext/src/system/system_info.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*****************************************************************************
* Copyright 2019 Serge Poltavsky. All rights reserved.
*
* This file may be distributed under the terms of GNU Public License version
* 3 (GPL v3) as defined by the Free Software Foundation (FSF). A copy of the
* license should have been included with this file, or the project in which
* this file belongs to. You may also find the details of GPL v3 at:
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* If you have any questions regarding the use of this file, feel free to
* contact the author of this file, or the owner of the project in which
* this file belongs to.
*****************************************************************************/
#include "system_info.h"
#include "ceammc_containers.h"
#include "ceammc_crc32.h"
#include "ceammc_factory.h"

CEAMMC_DEFINE_SYM(temp)

SystemInfo::SystemInfo(const PdArgs& args)
: DispatchedObject<BaseObject>(args)
, sysinfo_(nullptr, ceammc_sysinfo_free)
{
createOutlet();

sysinfo_.reset(ceammc_sysinfo_create(
{ //
this,
[](void* user, const char* label, float value) {
auto this_ = static_cast<SystemInfo*>(user);
if (this_) {
AtomArray<2> data { value, gensym(label) };
this_->anyTo(0, sym_temp(), data.view());
}
} },
{ subscriberId(), [](size_t id) { Dispatcher::instance().send({ id, 0 }); } }));
}

bool SystemInfo::notify(int)
{
if (sysinfo_)
return ceammc_sysinfo_process(sysinfo_.get());
else
return false;
}

void SystemInfo::m_temp(t_symbol* s, const AtomListView& lv)
{
if (sysinfo_)
ceammc_sysinfo_get_temperature(sysinfo_.get());
}

void setup_system_info()
{
ObjectFactory<SystemInfo> obj("system.info");
obj.addMethod("temp", &SystemInfo::m_temp);
}
34 changes: 34 additions & 0 deletions ceammc/ext/src/system/system_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*****************************************************************************
* Copyright 2024 Serge Poltavski. All rights reserved.
*
* This file may be distributed under the terms of GNU Public License version
* 3 (GPL v3) as defined by the Free Software Foundation (FSF). A copy of the
* license should have been included with this file, or the project in which
* this file belongs to. You may also find the details of GPL v3 at:
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* If you have any questions regarding the use of this file, feel free to
* contact the author of this file, or the owner of the project in which
* this file belongs to.
*****************************************************************************/
#ifndef SYSTEM_INFO_H
#define SYSTEM_INFO_H

#include "ceammc_object.h"
#include "ceammc_poll_dispatcher.h"
#include "system_rust.hpp"

#include <memory>
using namespace ceammc;

class SystemInfo : public DispatchedObject<BaseObject> {
std::unique_ptr<ceammc_system_info, void (*)(ceammc_system_info*)> sysinfo_;

public:
SystemInfo(const PdArgs& args);

bool notify(int) final;
void m_temp(t_symbol* s, const AtomListView& lv);
};

#endif // SYSTEM_INFO_H
3 changes: 2 additions & 1 deletion cmake/build_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(WITH_PD_INSTANCE "Build with PD_INSTANCE" OFF)
option(WITH_PRINTER "Build with printer support" ON)
option(WITH_SFIZZ "Build with Sfizz support" ON)
option(WITH_SYSTEM_CMD "Build system.cmd object" ON)
option(WITH_SYSTEM_INFO "Build system.info object" ON)
option(WITH_TELEGRAM "Build with telegram bot support" ON)
option(WITH_TTS_FLITE "Build with Flite TTS support" ON)
option(WITH_TTS_RHVOICE "Build with RHVoice TTS support" OFF)
Expand Down Expand Up @@ -55,7 +56,7 @@ else()
cmake_dependent_option(WITH_RUST_CORE "Use rust core module" ON "WITH_ZEROCONF" OFF)
cmake_dependent_option(WITH_RUST_HW "Use rust hardware module" ON "WITH_GAMEPAD OR WITH_PRINTER" OFF)
cmake_dependent_option(WITH_RUST_NET "Use rust net module" ON "WITH_MQTT OR WITH_HTTP OR WITH_FREESOUND OR WITH_TELEGRAM OR WITH_WEBSOCKET" OFF)
cmake_dependent_option(WITH_RUST_SYSTEM "Use rust system module" ON "WITH_SYSTEM_CMD" OFF)
cmake_dependent_option(WITH_RUST_SYSTEM "Use rust system module" ON "WITH_SYSTEM_CMD OR WITH_SYSTEM_INFO" OFF)
endif()


Expand Down

0 comments on commit 3fd28be

Please sign in to comment.