Line data Source code
1 : /** 2 : Copyright (c) 2024 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #include "SPWebHostComponent.h" 24 : 25 : namespace STAPPLER_VERSIONIZED stappler::web { 26 : 27 0 : HostComponent::Loader::Loader(const StringView &str, Symbol s) : name(str), loader(s) { } 28 : 29 25 : HostComponent::HostComponent(const Host &host, const HostComponentInfo &cfg) 30 25 : : _host(host) 31 25 : , _name(cfg.name.str<Interface>()) 32 25 : , _version(cfg.version.empty() ? String("1.0") : cfg.version.str<Interface>()) 33 50 : , _config(cfg.data) { 34 25 : if (_config.isString("version")) { 35 0 : _version = _config.getString("version"); 36 : } 37 25 : } 38 : 39 0 : void HostComponent::handleChildInit(const Host &serv) { } 40 : 41 0 : void HostComponent::handleStorageInit(const Host &, const db::Adapter &) { } 42 : 43 0 : void HostComponent::initTransaction(db::Transaction &) { } 44 : 45 0 : void HostComponent::handleHeartbeat(const Host &) { } 46 : 47 200 : const db::Scheme * HostComponent::exportScheme(const db::Scheme &scheme) { 48 200 : return _host.exportScheme(scheme); 49 : } 50 : 51 0 : void HostComponent::addCommand(const StringView &name, Function<Value(const StringView &)> &&cb, const StringView &desc, const StringView &help) { 52 0 : addOutputCommand(name, [cb] (StringView v, const Callback<void(const Value &)> &scb) -> bool { 53 0 : auto val = cb(v); 54 0 : if (!val.isNull()) { 55 0 : scb(val); 56 0 : return true; 57 : } 58 0 : return false; 59 0 : }, desc, help); 60 0 : } 61 : 62 25 : void HostComponent::addOutputCommand(const StringView &name, CommandCallback &&cb, const StringView &desc, const StringView &help) { 63 25 : _commands.emplace(name.str<Interface>(), Command{name.str<Interface>(), desc.str<Interface>(), help.str<Interface>(), move(cb)}); 64 25 : } 65 : 66 0 : const HostComponent::Command *HostComponent::getCommand(const StringView &name) const { 67 0 : auto it = _commands.find(name); 68 0 : if (it != _commands.end()) { 69 0 : return &it->second; 70 : } 71 0 : return nullptr; 72 : } 73 : 74 50 : const Map<String, HostComponent::Command> &HostComponent::getCommands() const { 75 50 : return _commands; 76 : } 77 : 78 : }