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 /** 62 * This class defines the base class for an OpenThread vendor Extension object. 63 * 64 * This class is used by OpenThread core to interact with the extension module. Methods in this class are expected 65 * to be implemented by the vendor extension module. 66 * 67 * Support for vendor extension can be enabled using `OPENTHREAD_ENABLE_VENDOR_EXTENSION` configuration option. 68 * 69 */ 70 class ExtensionBase : public InstanceLocator, private NonCopyable 71 { 72 public: 73 /** 74 * This static method initializes and gets a vendor extension instance. 75 * 76 * @param[in] aInstance A reference to the OpenThread instance. 77 * 78 * @note When this method is called, the @p aInstance itself may not yet be fully initialized. The method 79 * `SignalInstanceInit()` is called when `aInstance` is fully initialized. 80 * 81 * @returns A reference to the object. 82 * 83 */ 84 static ExtensionBase &Init(Instance &aInstance); 85 86 /** 87 * This method notifies the extension object that OpenThread instance has been initialized. 88 * 89 */ 90 void SignalInstanceInit(void); 91 92 /** 93 * This method notifies the extension object that NCP instance has been initialized. 94 * 95 * @param[in] aNcpInstance A reference to the NCP object. 96 * 97 */ 98 void SignalNcpInit(Ncp::NcpBase &aNcpInstance); 99 100 /** 101 * This method notifies the extension object of events from OpenThread `Notifier`. 102 * 103 * @param[in] aEvents The list of events emitted by `Notifier`. 104 * 105 */ 106 void HandleNotifierEvents(Events aEvents); 107 108 protected: 109 /** 110 * This constructor initializes the object. 111 * 112 * @param[in] aInstance A reference to the OpenThread instance. 113 * 114 */ ExtensionBase(Instance & aInstance)115 explicit ExtensionBase(Instance &aInstance) 116 : InstanceLocator(aInstance) 117 , mIsInitialized(true) 118 { 119 } 120 121 bool mIsInitialized; 122 }; 123 124 /** 125 * @} 126 * 127 */ 128 129 } // namespace Extension 130 } // namespace ot 131 132 #endif // #if OPENTHREAD_ENABLE_VENDOR_EXTENSION 133 134 #endif // EXTENSION_HPP_ 135