nexuslua
Loading...
Searching...
No Matches
agents.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2025 acrion innovations GmbH
3Authors: Stefan Zipproth, s.zipproth@acrion.ch
4
5This file is part of nexuslua, see https://github.com/acrion/nexuslua and https://nexuslua.org
6
7nexuslua is offered under a commercial and under the AGPL license.
8For commercial licensing, contact us at https://acrion.ch/sales. For AGPL licensing, see below.
9
10AGPL licensing:
11
12nexuslua is free software: you can redistribute it and/or modify
13it under the terms of the GNU Affero General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17nexuslua is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Affero General Public License for more details.
21
22You should have received a copy of the GNU Affero General Public License
23along with nexuslua. If not, see <https://www.gnu.org/licenses/>.
24*/
25
26#pragma once
27
28#include "cpp_handler.hpp"
29#include "lua_table.hpp"
31
32#include "nexuslua_export.h"
33
34#include <filesystem>
35#include <map>
36#include <memory>
37#include <string>
38
39namespace nexuslua
40{
41 class Agent;
42 class AgentCpp;
43 class AgentLua;
44 class PluginSpec;
45 class AgentMessage;
46
48 class NEXUSLUA_EXPORT agents : public std::enable_shared_from_this<agents>
49 {
50 struct impl;
51 std::unique_ptr<impl> _impl;
52
53 public:
55 virtual ~agents();
56
58 const std::map<std::string, std::shared_ptr<const Agent>>& GetPlugins();
60 PluginInstallResult InstallPlugin(const std::filesystem::path& srcFolder, std::string& errorMessage);
61 PluginInstallResult InstallPlugin(const std::shared_ptr<::nexuslua::Agent>& agent, const std::filesystem::path& srcFolder, std::string& errorMessage);
62 PluginUninstallResult UninstallPlugin(const std::string& name);
63 void RestorePersistentPluginFolder(const std::shared_ptr<::nexuslua::Agent>& plugin, const std::filesystem::path& srcFolder);
64 const AgentMessage& GetMessage(const std::string& agentName, const std::string& messageName);
65
71 std::shared_ptr<AgentCpp> Add(const std::string& agentName, const CppHandler& cppHandler, const LuaTable& predefinedTable = {});
72
78 std::shared_ptr<AgentLua> Add(const std::string& agentName, const std::filesystem::path& pathToLuaFile, const std::string& luaCode = "", const LuaTable& predefinedTable = {});
79
83 std::shared_ptr<Agent> GetAgent(const std::string& agentName);
84
88 void AddMessageForCppAgent(const std::string& agentName, const std::string& messageName);
91 static int64_t TotalSizeOfMessagesQueues();
92 };
93}
This class describes a message that can be sent via nexuslua send or AgentMessage::Send.
Definition agent_message.hpp:50
base class of the three types of agents
Definition agent.hpp:60
std::shared_ptr< AgentCpp > Add(const std::string &agentName, const CppHandler &cppHandler, const LuaTable &predefinedTable={})
creates a new hardware thread that calls cppHandler as soon as a message is sent to it via either nex...
std::shared_ptr< Agent > GetAgent(const std::string &agentName)
returns the Agent instance associated with the given agent name, or nullptr if there is no such agent
static int64_t TotalSizeOfMessagesQueues()
PluginInstallResult InstallPlugin(const std::filesystem::path &srcFolder, std::string &errorMessage)
user selects a directory with a plugin to be installed. This function installs it....
PluginInstallResult InstallPlugin(const std::shared_ptr<::nexuslua::Agent > &agent, const std::filesystem::path &srcFolder, std::string &errorMessage)
user selects a directory with a plugin to be installed. This function installs it....
void ShutdownAgents()
if the main application quits, it should use this function to make sure all threads have ended before...
void InvalidatePluginScan()
after calling this function, the next call to agents::GetPlugins will rescan the plugin directory
const AgentMessage & GetMessage(const std::string &agentName, const std::string &messageName)
return the given message
void WaitUntilMessageQueueIsEmpty()
wait until the nexuslua agents processed all remaining messages
PluginUninstallResult UninstallPlugin(const std::string &name)
the name is identical with AgentPlugin::GetName()
const std::map< std::string, std::shared_ptr< const Agent > > & GetPlugins()
key is plugin name, same as AgentPlugin::GetName()
void RestorePersistentPluginFolder(const std::shared_ptr<::nexuslua::Agent > &plugin, const std::filesystem::path &srcFolder)
copy the persistent subfolder from the given directory to the plugin folder
std::shared_ptr< AgentLua > Add(const std::string &agentName, const std::filesystem::path &pathToLuaFile, const std::string &luaCode="", const LuaTable &predefinedTable={})
creates a new hardware thread that calls luaCode, if not empty, otherwise the given lua file
virtual ~agents()
void AddMessageForCppAgent(const std::string &agentName, const std::string &messageName)
registers a message for an nexuslua::Agent that has been created via nexuslua::agents::Add.
The nexuslua library is implemented inside this namespace.
PluginInstallResult
result values of agents::InstallPlugin
Definition plugin_install_result.hpp:34
std::function< void(std::shared_ptr< Message >)> CppHandler
the signature of a function that is called whenever a C++ nexuslua::agent receives a message
Definition cpp_handler.hpp:38
This type is used for the parameters of nexuslua::Message. In its serialized representation,...
Definition lua_table.hpp:54
result values of agents::UninstallPlugin
Definition plugin_install_result.hpp:45