Loading threadnetwork/aidl/default/socket_interface.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ namespace android { namespace hardware { namespace threadnetwork { const char SocketInterface::kLogModuleName[] = "SocketIntface"; SocketInterface::SocketInterface(const ot::Url::Url& aRadioUrl) : mReceiveFrameCallback(nullptr), mReceiveFrameContext(nullptr), Loading Loading @@ -157,7 +159,7 @@ void SocketInterface::Read(void) { } else if (rval < 0) { DieNow(OT_EXIT_ERROR_ERRNO); } else { otLogCritPlat("Socket connection is closed by remote."); LogCrit("Socket connection is closed by remote."); exit(OT_EXIT_FAILURE); } } Loading Loading @@ -192,7 +194,7 @@ void SocketInterface::HandleSocketFrame(otError aError) { mReceiveFrameCallback(mReceiveFrameContext); } else { mReceiveFrameBuffer->DiscardFrame(); otLogWarnPlat("Process socket frame failed: %s", otThreadErrorToString(aError)); LogWarn("Process socket frame failed: %s", otThreadErrorToString(aError)); } exit: Loading @@ -204,16 +206,16 @@ int SocketInterface::OpenFile(const ot::Url::Url& aRadioUrl) { sockaddr_un serverAddress; VerifyOrExit(sizeof(serverAddress.sun_path) > strlen(aRadioUrl.GetPath()), otLogCritPlat("Invalid file path length")); LogCrit("Invalid file path length")); strncpy(serverAddress.sun_path, aRadioUrl.GetPath(), sizeof(serverAddress.sun_path)); serverAddress.sun_family = AF_UNIX; fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); VerifyOrExit(fd != -1, otLogCritPlat("open(): errno=%s", strerror(errno))); VerifyOrExit(fd != -1, LogCrit("open(): errno=%s", strerror(errno))); if (connect(fd, reinterpret_cast<struct sockaddr*>(&serverAddress), sizeof(serverAddress)) == -1) { otLogCritPlat("connect(): errno=%s", strerror(errno)); LogCrit("connect(): errno=%s", strerror(errno)); close(fd); fd = -1; } Loading @@ -225,9 +227,9 @@ exit: void SocketInterface::CloseFile(void) { VerifyOrExit(mSockFd != -1); VerifyOrExit(0 == close(mSockFd), otLogCritPlat("close(): errno=%s", strerror(errno))); VerifyOrExit(0 == close(mSockFd), LogCrit("close(): errno=%s", strerror(errno))); VerifyOrExit(wait(nullptr) != -1 || errno == ECHILD, otLogCritPlat("wait(): errno=%s", strerror(errno))); LogCrit("wait(): errno=%s", strerror(errno))); mSockFd = -1; Loading @@ -254,7 +256,7 @@ void SocketInterface::WaitForSocketFileCreated(const char* aPath) { wd = inotify_add_watch(inotifyFd, folderPath.c_str(), IN_CREATE); VerifyOrDie(wd != -1, OT_EXIT_ERROR_ERRNO); otLogInfoPlat("Waiting for socket file %s be created...", aPath); LogInfo("Waiting for socket file %s be created...", aPath); while (true) { fd_set fds; Loading Loading @@ -286,7 +288,7 @@ void SocketInterface::WaitForSocketFileCreated(const char* aPath) { close(inotifyFd); exit: otLogInfoPlat("Socket file: %s is created", aPath); LogInfo("Socket file: %s is created", aPath); return; } Loading threadnetwork/aidl/default/socket_interface.hpp +5 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include "lib/spinel/spinel_interface.hpp" #include "lib/url/url.hpp" #include "logger.hpp" namespace aidl { namespace android { Loading @@ -32,8 +33,11 @@ namespace threadnetwork { * Defines a Socket interface to the Radio Co-processor (RCP) * */ class SocketInterface : public ot::Spinel::SpinelInterface { class SocketInterface : public ot::Spinel::SpinelInterface, public ot::Posix::Logger<SocketInterface> { public: static const char kLogModuleName[]; ///< Module name used for logging. /** * Initializes the object. * Loading threadnetwork/aidl/default/utils.cpp +13 −31 Original line number Diff line number Diff line Loading @@ -20,43 +20,25 @@ #include <openthread/platform/alarm-milli.h> #include <utils/Log.h> void otLogCritPlat(const char* format, ...) { va_list args; void otLogPlatArgs(otLogLevel aLogLevel, const char* aPlatModuleName, const char* aFormat, va_list aArgs) { OT_UNUSED_VARIABLE(aPlatModuleName); static const android_LogPriority kLogPriorities[] = {ANDROID_LOG_SILENT, ANDROID_LOG_FATAL, ANDROID_LOG_WARN, ANDROID_LOG_INFO, ANDROID_LOG_INFO, ANDROID_LOG_DEBUG}; va_start(args, format); __android_log_vprint(ANDROID_LOG_FATAL, LOG_TAG, format, args); va_end(args); if (aLogLevel >= sizeof(kLogPriorities) / sizeof(android_LogPriority)) { return; } void otLogWarnPlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, args); va_end(args); __android_log_vprint(kLogPriorities[aLogLevel], LOG_TAG, aFormat, aArgs); } void otLogNotePlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); va_end(args); } void otLogInfoPlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); va_end(args); } void otLogDebgPlat(const char* format, ...) { void otLogCritPlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, args); __android_log_vprint(ANDROID_LOG_FATAL, LOG_TAG, format, args); va_end(args); } Loading Loading
threadnetwork/aidl/default/socket_interface.cpp +11 −9 Original line number Diff line number Diff line Loading @@ -42,6 +42,8 @@ namespace android { namespace hardware { namespace threadnetwork { const char SocketInterface::kLogModuleName[] = "SocketIntface"; SocketInterface::SocketInterface(const ot::Url::Url& aRadioUrl) : mReceiveFrameCallback(nullptr), mReceiveFrameContext(nullptr), Loading Loading @@ -157,7 +159,7 @@ void SocketInterface::Read(void) { } else if (rval < 0) { DieNow(OT_EXIT_ERROR_ERRNO); } else { otLogCritPlat("Socket connection is closed by remote."); LogCrit("Socket connection is closed by remote."); exit(OT_EXIT_FAILURE); } } Loading Loading @@ -192,7 +194,7 @@ void SocketInterface::HandleSocketFrame(otError aError) { mReceiveFrameCallback(mReceiveFrameContext); } else { mReceiveFrameBuffer->DiscardFrame(); otLogWarnPlat("Process socket frame failed: %s", otThreadErrorToString(aError)); LogWarn("Process socket frame failed: %s", otThreadErrorToString(aError)); } exit: Loading @@ -204,16 +206,16 @@ int SocketInterface::OpenFile(const ot::Url::Url& aRadioUrl) { sockaddr_un serverAddress; VerifyOrExit(sizeof(serverAddress.sun_path) > strlen(aRadioUrl.GetPath()), otLogCritPlat("Invalid file path length")); LogCrit("Invalid file path length")); strncpy(serverAddress.sun_path, aRadioUrl.GetPath(), sizeof(serverAddress.sun_path)); serverAddress.sun_family = AF_UNIX; fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); VerifyOrExit(fd != -1, otLogCritPlat("open(): errno=%s", strerror(errno))); VerifyOrExit(fd != -1, LogCrit("open(): errno=%s", strerror(errno))); if (connect(fd, reinterpret_cast<struct sockaddr*>(&serverAddress), sizeof(serverAddress)) == -1) { otLogCritPlat("connect(): errno=%s", strerror(errno)); LogCrit("connect(): errno=%s", strerror(errno)); close(fd); fd = -1; } Loading @@ -225,9 +227,9 @@ exit: void SocketInterface::CloseFile(void) { VerifyOrExit(mSockFd != -1); VerifyOrExit(0 == close(mSockFd), otLogCritPlat("close(): errno=%s", strerror(errno))); VerifyOrExit(0 == close(mSockFd), LogCrit("close(): errno=%s", strerror(errno))); VerifyOrExit(wait(nullptr) != -1 || errno == ECHILD, otLogCritPlat("wait(): errno=%s", strerror(errno))); LogCrit("wait(): errno=%s", strerror(errno))); mSockFd = -1; Loading @@ -254,7 +256,7 @@ void SocketInterface::WaitForSocketFileCreated(const char* aPath) { wd = inotify_add_watch(inotifyFd, folderPath.c_str(), IN_CREATE); VerifyOrDie(wd != -1, OT_EXIT_ERROR_ERRNO); otLogInfoPlat("Waiting for socket file %s be created...", aPath); LogInfo("Waiting for socket file %s be created...", aPath); while (true) { fd_set fds; Loading Loading @@ -286,7 +288,7 @@ void SocketInterface::WaitForSocketFileCreated(const char* aPath) { close(inotifyFd); exit: otLogInfoPlat("Socket file: %s is created", aPath); LogInfo("Socket file: %s is created", aPath); return; } Loading
threadnetwork/aidl/default/socket_interface.hpp +5 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include "lib/spinel/spinel_interface.hpp" #include "lib/url/url.hpp" #include "logger.hpp" namespace aidl { namespace android { Loading @@ -32,8 +33,11 @@ namespace threadnetwork { * Defines a Socket interface to the Radio Co-processor (RCP) * */ class SocketInterface : public ot::Spinel::SpinelInterface { class SocketInterface : public ot::Spinel::SpinelInterface, public ot::Posix::Logger<SocketInterface> { public: static const char kLogModuleName[]; ///< Module name used for logging. /** * Initializes the object. * Loading
threadnetwork/aidl/default/utils.cpp +13 −31 Original line number Diff line number Diff line Loading @@ -20,43 +20,25 @@ #include <openthread/platform/alarm-milli.h> #include <utils/Log.h> void otLogCritPlat(const char* format, ...) { va_list args; void otLogPlatArgs(otLogLevel aLogLevel, const char* aPlatModuleName, const char* aFormat, va_list aArgs) { OT_UNUSED_VARIABLE(aPlatModuleName); static const android_LogPriority kLogPriorities[] = {ANDROID_LOG_SILENT, ANDROID_LOG_FATAL, ANDROID_LOG_WARN, ANDROID_LOG_INFO, ANDROID_LOG_INFO, ANDROID_LOG_DEBUG}; va_start(args, format); __android_log_vprint(ANDROID_LOG_FATAL, LOG_TAG, format, args); va_end(args); if (aLogLevel >= sizeof(kLogPriorities) / sizeof(android_LogPriority)) { return; } void otLogWarnPlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, args); va_end(args); __android_log_vprint(kLogPriorities[aLogLevel], LOG_TAG, aFormat, aArgs); } void otLogNotePlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); va_end(args); } void otLogInfoPlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args); va_end(args); } void otLogDebgPlat(const char* format, ...) { void otLogCritPlat(const char* format, ...) { va_list args; va_start(args, format); __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, args); __android_log_vprint(ANDROID_LOG_FATAL, LOG_TAG, format, args); va_end(args); } Loading