1 /* 2 * Copyright (c) 2018, 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 definitions for OpenThread vendor extension hooks. 32 */ 33 34 #ifndef EXTENSION_HPP_ 35 #define EXTENSION_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #if OPENTHREAD_ENABLE_VENDOR_EXTENSION 40 41 #include "common/locator.hpp" 42 #include "common/non_copyable.hpp" 43 #include "common/notifier.hpp" 44 45 namespace ot { 46 namespace Ncp { 47 class NcpBase; 48 } 49 namespace Extension { 50 51 /** 52 * @addtogroup core-extension 53 * 54 * @brief 55 * This module includes definitions for OpenThread vendor extension hooks. 56 * 57 * @{ 58 */ 59 60 /** 61 * Defines the base class for an OpenThread vendor Extension object. 62 * 63 * Is used by OpenThread core to interact with the extension module. Methods in this class are expected 64 * to be implemented by the vendor extension module. 65 * 66 * Support for vendor extension can be enabled using `OPENTHREAD_ENABLE_VENDOR_EXTENSION` configuration option. 67 */ 68 class ExtensionBase : public InstanceLocator, private NonCopyable 69 { 70 public: 71 /** 72 * Initializes and gets a vendor extension instance. 73 * 74 * @param[in] aInstance A reference to the OpenThread instance. 75 * 76 * @note When this method is called, the @p aInstance itself may not yet be fully initialized. The method 77 * `SignalInstanceInit()` is called when `aInstance` is fully initialized. 78 * 79 * @returns A reference to the object. 80 */ 81 static ExtensionBase &Init(Instance &aInstance); 82 83 /** 84 * Notifies the extension object that OpenThread instance has been initialized. 85 */ 86 void SignalInstanceInit(void); 87 88 /** 89 * Notifies the extension object that NCP instance has been initialized. 90 * 91 * @param[in] aNcpInstance A reference to the NCP object. 92 */ 93 void SignalNcpInit(Ncp::NcpBase &aNcpInstance); 94 95 /** 96 * Notifies the extension object of events from OpenThread `Notifier`. 97 * 98 * @param[in] aEvents The list of events emitted by `Notifier`. 99 */ 100 void HandleNotifierEvents(Events aEvents); 101 102 protected: 103 /** 104 * Initializes the object. 105 * 106 * @param[in] aInstance A reference to the OpenThread instance. 107 */ ExtensionBase(Instance & aInstance)108 explicit ExtensionBase(Instance &aInstance) 109 : InstanceLocator(aInstance) 110 , mIsInitialized(true) 111 { 112 } 113 114 bool mIsInitialized; 115 }; 116 117 /** 118 * @} 119 */ 120 121 } // namespace Extension 122 } // namespace ot 123 124 #endif // #if OPENTHREAD_ENABLE_VENDOR_EXTENSION 125 126 #endif // EXTENSION_HPP_ 127