nexuslua
Loading...
Searching...
No Matches
agent.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 "agent_message.hpp"
29
30#include "lua_table.hpp"
31
32#include "agents.hpp"
33#include "cpp_handler.hpp"
34#include "message.hpp"
35
36#include "nexuslua_export.h"
37
38#include <filesystem>
39#include <functional>
40#include <map>
41#include <memory>
42#include <string>
43
46namespace nexuslua
47{
48 class Agent;
49 class Configuration;
50
51 namespace LuaExtension
52 {
53 void AddMessage(Agent* agent, const std::string& luaPath, const std::string& messageName, const LuaTable& parameters);
54 void RegisterTableForAgent(const Agent* agent, const nexuslua::LuaTable& table);
55 }
56
59 class NEXUSLUA_EXPORT Agent
60 {
61 struct Impl;
62 std::unique_ptr<Impl> _impl;
63
64 public:
65 Agent(const std::shared_ptr<agents>& agents);
66 virtual ~Agent();
67
68 virtual std::string GetName() const = 0;
69 virtual std::filesystem::path GetInstallFolder() const;
70 virtual std::filesystem::path GetPersistentFolder() const;
71 virtual std::string GetVersionOnline() const;
72 virtual std::string GetVersionInstalled() const;
73 virtual bool IsFreeware() const;
74 virtual std::string GetUrlHelp() const;
75 virtual std::string GetUrlDownload() const;
76 virtual std::string GetUrlLicense() const;
77 virtual std::string GetUrlPurchase() const;
78 virtual std::string GetLicensee() const;
79 virtual const std::map<std::string, AgentMessage>& GetMessages() const;
80 virtual const AgentMessage& GetMessage(const std::string& messageName) const;
81 int GetId() const;
82
84 std::shared_ptr<agents> GetAgents();
85
86 protected:
87 void Start(const std::filesystem::path& luaPath, const std::string& luaCode);
88 void Start(const CppHandler& cppHandler);
89 virtual void AddMessage(const std::string& messageName, const LuaTable::nested_tables& parameterDescriptions, const std::string& displayName, const std::string& description, const std::string& icon);
90
91 std::map<std::string, AgentMessage> _messages;
92 friend void ::nexuslua::LuaExtension::AddMessage(Agent* agent, const std::string& luaPath, const std::string& messageName, const LuaTable& parameters);
93 };
94}
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
virtual std::filesystem::path GetInstallFolder() const
if this agent is installed as a plugin, return its installation folder, otherwise an empty string
std::shared_ptr< agents > GetAgents()
virtual bool IsFreeware() const
if this agent is installed as a plugin, return if it is freeware, otherwise false
Configuration & GetConfiguration()
void Start(const std::filesystem::path &luaPath, const std::string &luaCode)
virtual const AgentMessage & GetMessage(const std::string &messageName) const
return the message with the given name that this agent accepts
int GetId() const
returns a unique ID of this agent
virtual std::string GetUrlLicense() const
if this agent is installed as a plugin, return an URL with license information, otherwise an empty st...
virtual std::string GetLicensee() const
if this agent is installed as a plugin and a license file has been installed, return the licensee,...
Agent(const std::shared_ptr< agents > &agents)
virtual void AddMessage(const std::string &messageName, const LuaTable::nested_tables &parameterDescriptions, const std::string &displayName, const std::string &description, const std::string &icon)
virtual std::filesystem::path GetPersistentFolder() const
if this agent is installed as a plugin, return the sub folder inside the installation folder that per...
virtual std::string GetUrlPurchase() const
if this agent is installed as a plugin, return an URL where you can purchase a license,...
virtual std::string GetUrlHelp() const
if this agent is installed as a plugin, return the URL that contains help about it,...
virtual std::string GetVersionOnline() const
if this agent is installed as a plugin, return the online version, otherwise an empty string
std::map< std::string, AgentMessage > _messages
Definition agent.hpp:91
virtual const std::map< std::string, AgentMessage > & GetMessages() const
return a reference to all of the messages this agent supports, using the message name as key
virtual std::string GetName() const =0
return the name of the agent
virtual std::string GetVersionInstalled() const
if this agent is installed as a plugin, return its installed version, otherwise an empty string
virtual ~Agent()
virtual std::string GetUrlDownload() const
if this agent is installed as a plugin, return its download URL, otherwise an empty string
void Start(const CppHandler &cppHandler)
stores internal and user configuration
Definition configuration.hpp:42
Functions related to agents or plugins, which are (un-)installable agents with meta data like a versi...
Definition agents.hpp:49
Definition agent.hpp:52
void RegisterTableForAgent(const Agent *agent, const nexuslua::LuaTable &table)
void AddMessage(Agent *agent, const std::string &luaPath, const std::string &messageName, const LuaTable &parameters)
Definition description.hpp:33
The nexuslua library is implemented inside this namespace.
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