1 /* 2 * Copyright (c) 2021, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * This file includes definition for OTBR Agent. 32 */ 33 34 #ifndef OTBR_AGENT_APPLICATION_HPP_ 35 #define OTBR_AGENT_APPLICATION_HPP_ 36 37 #include <atomic> 38 #include <signal.h> 39 #include <stdint.h> 40 #include <vector> 41 42 #if OTBR_ENABLE_BORDER_AGENT 43 #include "border_agent/border_agent.hpp" 44 #endif 45 #include "ncp/ncp_openthread.hpp" 46 #if OTBR_ENABLE_BACKBONE_ROUTER 47 #include "backbone_router/backbone_agent.hpp" 48 #endif 49 #if OTBR_ENABLE_REST_SERVER 50 #include "rest/rest_web_server.hpp" 51 #endif 52 #if OTBR_ENABLE_DBUS_SERVER 53 #include "dbus/server/dbus_agent.hpp" 54 #endif 55 #if OTBR_ENABLE_OPENWRT 56 #include "openwrt/ubus/otubus.hpp" 57 #endif 58 #if OTBR_ENABLE_VENDOR_SERVER 59 #include "agent/vendor.hpp" 60 #endif 61 #include "utils/infra_link_selector.hpp" 62 63 namespace otbr { 64 65 /** 66 * @addtogroup border-router-agent 67 * 68 * @brief 69 * This module includes definition for OTBR application. 70 * 71 * @{ 72 */ 73 74 /** 75 * This class implements OTBR application management. 76 * 77 */ 78 class Application : private NonCopyable 79 { 80 public: 81 /** 82 * This constructor initializes the Application instance. 83 * 84 * @param[in] aInterfaceName Name of the Thread network interface. 85 * @param[in] aBackboneInterfaceName Name of the backbone network interface. 86 * @param[in] aRadioUrls The radio URLs (can be IEEE802.15.4 or TREL radio). 87 * @param[in] aEnableAutoAttach Whether or not to automatically attach to the saved network. 88 * 89 */ 90 explicit Application(const std::string & aInterfaceName, 91 const std::vector<const char *> &aBackboneInterfaceNames, 92 const std::vector<const char *> &aRadioUrls, 93 bool aEnableAutoAttach); 94 95 /** 96 * This method initializes the Application instance. 97 * 98 */ 99 void Init(void); 100 101 /** 102 * This method de-initializes the Application instance. 103 * 104 */ 105 void Deinit(void); 106 107 /** 108 * This method runs the application until exit. 109 * 110 * @retval OTBR_ERROR_NONE The application exited without any error. 111 * @retval OTBR_ERROR_ERRNO The application exited with some system error. 112 * 113 */ 114 otbrError Run(void); 115 116 private: 117 // Default poll timeout. 118 static const struct timeval kPollTimeout; 119 120 static void HandleSignal(int aSignal); 121 122 std::string mInterfaceName; 123 #if __linux__ 124 otbr::Utils::InfraLinkSelector mInfraLinkSelector; 125 #endif 126 const char * mBackboneInterfaceName; 127 Ncp::ControllerOpenThread mNcp; 128 #if OTBR_ENABLE_BORDER_AGENT 129 BorderAgent mBorderAgent; 130 #endif 131 #if OTBR_ENABLE_BACKBONE_ROUTER 132 BackboneRouter::BackboneAgent mBackboneAgent; 133 #endif 134 #if OTBR_ENABLE_OPENWRT 135 ubus::UBusAgent mUbusAgent; 136 #endif 137 #if OTBR_ENABLE_REST_SERVER 138 rest::RestWebServer mRestWebServer; 139 #endif 140 #if OTBR_ENABLE_DBUS_SERVER 141 DBus::DBusAgent mDBusAgent; 142 #endif 143 #if OTBR_ENABLE_VENDOR_SERVER 144 vendor::VendorServer mVendorServer; 145 #endif 146 147 static std::atomic_bool sShouldTerminate; 148 }; 149 150 /** 151 * @} 152 */ 153 154 } // namespace otbr 155 156 #endif // OTBR_AGENT_APPLICATION_HPP_ 157