From 2770867c97e60359ce7c3d85da4bfa500b6ecc3a Mon Sep 17 00:00:00 2001 From: James Benton Date: Mon, 11 Jun 2018 17:34:05 +0100 Subject: [PATCH] nn_ac: Move to nn/ac and start the C++ API. --- include/nn/ac.h | 9 + include/{nn_ac/nn_ac.h => nn/ac/ac_c.h} | 15 +- include/nn/ac/ac_cpp.h | 68 ++++++ include/nn/result.h | 305 ++++++++++++++++++++++++ 4 files changed, 387 insertions(+), 10 deletions(-) create mode 100644 include/nn/ac.h rename include/{nn_ac/nn_ac.h => nn/ac/ac_c.h} (74%) create mode 100644 include/nn/ac/ac_cpp.h create mode 100644 include/nn/result.h diff --git a/include/nn/ac.h b/include/nn/ac.h new file mode 100644 index 0000000..bcbae91 --- /dev/null +++ b/include/nn/ac.h @@ -0,0 +1,9 @@ +#pragma once + +/** + * \defgroup nn_ac Auto Connect + */ + +#include "ac/ac_c.h" +#include "ac/ac_cpp.h" +#include "ac/ac_types.h" diff --git a/include/nn_ac/nn_ac.h b/include/nn/ac/ac_c.h similarity index 74% rename from include/nn_ac/nn_ac.h rename to include/nn/ac/ac_c.h index c88f558..e7d2698 100644 --- a/include/nn_ac/nn_ac.h +++ b/include/nn/ac/ac_c.h @@ -1,8 +1,8 @@ #pragma once #include +#include /** - * \defgroup nn_ac Auto Connect * \ingroup nn_ac * @{ */ @@ -11,26 +11,21 @@ extern "C" { #endif -typedef enum ACResult -{ - OK = 0, -} ACResult; - typedef uint32_t ACConfigId; -ACResult +NNResult ACInitialize(); void ACFinalize(); -ACResult +NNResult ACGetStartupId(ACConfigId *configId); -ACResult +NNResult ACConnectWithConfigId(ACConfigId configId); -ACResult +NNResult ACGetAssignedAddress(uint32_t *ip); #ifdef __cplusplus diff --git a/include/nn/ac/ac_cpp.h b/include/nn/ac/ac_cpp.h new file mode 100644 index 0000000..bb3a9ce --- /dev/null +++ b/include/nn/ac/ac_cpp.h @@ -0,0 +1,68 @@ +#pragma once +#include +#include + +/** + * \ingroup nn_ac + * @{ + */ + +#ifdef __cplusplus + +namespace nn +{ +namespace ac +{ + +typedef uint32_t ConfigIdNum; + +namespace detail +{ +extern "C" +{ + +nn::Result Initialize__Q2_2nn2acFv(); +void Finalize__Q2_2nn2acFv(); +nn::Result GetStartupId__Q2_2nn2acFPQ3_2nn2ac11ConfigIdNum(ConfigIdNum *id); +nn::Result Connect__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum(ConfigIdNum id); +nn::Result GetAssignedAddress__Q2_2nn2acFPUl(uint32_t *ip); + +} // extern "C" +} // namespace detail + +static inline nn::Result +Initialize() +{ + return detail::Initialize__Q2_2nn2acFv(); +} + +static inline void +Finalize() +{ + return detail::Finalize__Q2_2nn2acFv(); +} + +static inline nn::Result +GetStartupId(ConfigIdNum *id) +{ + return detail::GetStartupId__Q2_2nn2acFPQ3_2nn2ac11ConfigIdNum(id); +} + +static inline nn::Result +Connect(ConfigIdNum id) +{ + return detail::Connect__Q2_2nn2acFQ3_2nn2ac11ConfigIdNum(id); +} + +static inline nn::Result +GetAssignedAddress(uint32_t *ip) +{ + return detail::GetAssignedAddress__Q2_2nn2acFPUl(ip); +} + +} // namespace ac +} // namespace nn + +#endif // ifdef __cplusplus + +/** @} */ diff --git a/include/nn/result.h b/include/nn/result.h new file mode 100644 index 0000000..914d4dc --- /dev/null +++ b/include/nn/result.h @@ -0,0 +1,305 @@ +#pragma once +#include + +/** + * \defgroup nn Result + * \ingroup nn + * @{ + */ + +/** + * C equivalent of the C++ nn::Result + */ +typedef struct NNResult NNResult; + +struct NNResult +{ + int32_t value; +}; + +static inline int NNResult_IsSuccess(NNResult result) +{ + return result.value >= 0; +} + +static inline int NNResult_IsFailure(NNResult result) +{ + return result.value < 0; +} + +#ifdef __cplusplus + +namespace nn +{ + +/** + * Result value type used by nn libraries. + */ +class Result +{ +public: + enum Level + { + LEVEL_SUCCESS = 0, + LEVEL_FATAL = -1, + LEVEL_USAGE = -2, + LEVEL_STATUS = -3, + LEVEL_END = -7, + }; + + enum LegacyLevel + { + LEVEL_INFO = 1, + LEVEL_RESET = -4, + LEVEL_REINIT = -5, + LEVEL_PERMANENT = -6, + LEVEL_TEMPORARY = -7, + }; + + enum Module + { + RESULT_MODULE_COMMON = 0, + RESULT_MODULE_NN_IPC = 1, + RESULT_MODULE_NN_BOSS = 2, + RESULT_MODULE_NN_ACP = 3, + RESULT_MODULE_NN_IOS = 4, + RESULT_MODULE_NN_NIM = 5, + RESULT_MODULE_NN_PDM = 6, + RESULT_MODULE_NN_ACT = 7, + RESULT_MODULE_NN_NGC = 8, + RESULT_MODULE_NN_ECA = 9, + RESULT_MODULE_NN_NUP = 10, + RESULT_MODULE_NN_NDM = 11, + RESULT_MODULE_NN_FP = 12, + RESULT_MODULE_NN_AC = 13, + RESULT_MODULE_NN_CONNTEST = 14, + RESULT_MODULE_NN_DRMAPP = 15, + RESULT_MODULE_NN_TELNET = 16, + RESULT_MODULE_NN_OLV = 17, + RESULT_MODULE_NN_VCTL = 18, + RESULT_MODULE_NN_NEIA = 19, + RESULT_MODULE_NN_SPM = 20, + RESULT_MODULE_NN_TEST = 125, + }; + + enum LegacyModule + { + MODULE_COMMON = 0, + MODULE_NN_KERNEL = 1, + MODULE_NN_UTIL = 2, + MODULE_NN_FILE_SERVER = 3, + MODULE_NN_LOADER_SERVER = 4, + MODULE_NN_TCB = 5, + MODULE_NN_OS = 6, + MODULE_NN_DBG = 7, + MODULE_NN_DMNT = 8, + MODULE_NN_PDN = 9, + MODULE_NN_GX = 0xA, + MODULE_NN_I2C = 0xB, + MODULE_NN_GPIO = 0xC, + MODULE_NN_DD = 0xD, + MODULE_NN_CODEC = 0xE, + MODULE_NN_SPI = 0xF, + MODULE_NN_PXI = 0x10, + MODULE_NN_FS = 0x11, + MODULE_NN_DI = 0x12, + MODULE_NN_HID = 0x13, + MODULE_NN_CAMERA = 0x14, + MODULE_NN_PI = 0x15, + MODULE_NN_PM = 0x16, + MODULE_NN_PMLOW = 0x17, + MODULE_NN_FSI = 0x18, + MODULE_NN_SRV = 0x19, + MODULE_NN_NDM = 0x1A, + MODULE_NN_NWM = 0x1B, + MODULE_NN_SOCKET = 0x1C, + MODULE_NN_LDR = 0x1D, + MODULE_NN_ACC = 0x1E, + MODULE_NN_ROMFS = 0x1F, + MODULE_NN_AM = 0x20, + MODULE_NN_HIO = 0x21, + MODULE_NN_UPDATER = 0x22, + MODULE_NN_MIC = 0x23, + MODULE_NN_FND = 0x24, + MODULE_NN_MP = 0x25, + MODULE_NN_MPWL = 0x26, + MODULE_NN_AC = 0x27, + MODULE_NN_HTTP = 0x28, + MODULE_NN_DSP = 0x29, + MODULE_NN_SND = 0x2A, + MODULE_NN_DLP = 0x2B, + MODULE_NN_HIOLOW = 0x2C, + MODULE_NN_CSND = 0x2D, + MODULE_NN_SSL = 0x2E, + MODULE_NN_AMLOW = 0x2F, + MODULE_NN_NEX = 0x30, + MODULE_NN_FRIENDS = 0x31, + MODULE_NN_RDT = 0x32, + MODULE_NN_APPLET = 0x33, + MODULE_NN_NIM = 0x34, + MODULE_NN_PTM = 0x35, + MODULE_NN_MIDI = 0x36, + MODULE_NN_MC = 0x37, + MODULE_NN_SWC = 0x38, + MODULE_NN_FATFS = 0x39, + MODULE_NN_NGC = 0x3A, + MODULE_NN_CARD = 0x3B, + MODULE_NN_CARDNOR = 0x3C, + MODULE_NN_SDMC = 0x3D, + MODULE_NN_BOSS = 0x3E, + MODULE_NN_DBM = 0x3F, + MODULE_NN_CFG = 0x40, + MODULE_NN_PS = 0x41, + MODULE_NN_CEC = 0x42, + MODULE_NN_IR = 0x43, + MODULE_NN_UDS = 0x44, + MODULE_NN_PL = 0x45, + MODULE_NN_CUP = 0x46, + MODULE_NN_GYROSCOPE = 0x47, + MODULE_NN_MCU = 0x48, + MODULE_NN_NS = 0x49, + MODULE_NN_NEWS = 0x4A, + MODULE_NN_RO = 0x4B, + MODULE_NN_GD = 0x4C, + MODULE_NN_CARDSPI = 0x4D, + MODULE_NN_EC = 0x4E, + MODULE_NN_WEBBRS = 0x4F, + MODULE_NN_TEST = 0x50, + MODULE_NN_ENC = 0x51, + MODULE_NN_PIA = 0x52, + MODULE_APPLICATION = 0x1FE, + }; + + enum LegacySummary + { + SUMMARY_SUCCESS = 0, + SUMMARY_NOTHING_HAPPENED = 1, + SUMMARY_WOULD_BLOCK = 2, + SUMMARY_OUT_OF_RESOURCE = 3, + SUMMARY_NOT_FOUND = 4, + SUMMARY_INVALID_STATE = 5, + SUMMARY_NOT_SUPPORTED = 6, + SUMMARY_INVALID_ARGUMENT = 7, + SUMMARY_WRONG_ARGUMENT = 8, + SUMMARY_CANCELLED = 9, + SUMMARY_STATUS_CHANGED = 10, + SUMMARY_INTERNAL = 11, + }; + + enum LegacySignature + { + SIGNATURE_IS_LEGACY = 3, + }; + +public: + Result(Level level, Module module, unsigned description) : + mLevel(level), + mModule(module), + mDescription(description) + { + } + + Result(const NNResult &result) : + mValue(result.value) + { + } + + bool IsFailure() const + { + return !IsSuccess(); + } + + bool IsSuccess() const + { + return mLevel >= 0; + } + + bool IsLegacy() const + { + return mLegacy.signature == SIGNATURE_IS_LEGACY; + } + + unsigned GetDescription() const + { + if (IsLegacy()) { + return mLegacy.description; + } + + return mDescription; + } + + int GetLevel() const + { + if (IsLegacy()) { + return mLegacy.level; + } + + return mLevel; + } + + unsigned GetModule() const + { + if (IsLegacy()) { + return mLegacy.module; + } + + return mModule; + } + + unsigned GetSummary() const + { + if (IsLegacy()) { + return mLegacy.summary; + } + + return 0; + } + + operator bool() const + { + return IsSuccess(); + } + + operator NNResult() const + { + NNResult result; + result.value = mValue; + return result; + } + + bool operator==(const Result &other) const + { + return mValue == other.mValue; + } + + bool operator!=(const Result &other) const + { + return mValue != other.mValue; + } + +private: + union { + struct { + uint32_t description : 10; + uint32_t summary : 4; + int32_t level : 4; + uint32_t : 2; + uint32_t module : 7; + uint32_t signature : 2; + } mLegacy; + + struct { + uint32_t mDescription : 20; + uint32_t mModule : 9; + int32_t mLevel : 3; + }; + + int32_t mValue; + }; +}; + +} // namespace nn + +#endif // ifdef __cplusplus + +/** @} */