[threadnetwork] update the platform log API usages and implementations

The latest OpenThread has updated the usage of the platform log APIs.
This CL updates the log APIs usages and implementations.

Bug: b/333301206
Test: Run ThreadNetwork HAL and check logs.
Change-Id: I0c0999edbed1c041e2752d195e753d02b2c734f4
This commit is contained in:
Zhanglong Xia 2024-04-08 17:07:57 +08:00
parent 0c2179c224
commit 3c153add59
3 changed files with 30 additions and 42 deletions

View file

@ -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),
@ -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);
}
}
@ -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:
@ -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;
}
@ -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;
@ -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;
@ -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;
}

View file

@ -22,6 +22,7 @@
#include "lib/spinel/spinel_interface.hpp"
#include "lib/url/url.hpp"
#include "logger.hpp"
namespace aidl {
namespace android {
@ -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.
*

View file

@ -20,6 +20,20 @@
#include <openthread/platform/alarm-milli.h>
#include <utils/Log.h>
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};
if (aLogLevel >= sizeof(kLogPriorities) / sizeof(android_LogPriority)) {
return;
}
__android_log_vprint(kLogPriorities[aLogLevel], LOG_TAG, aFormat, aArgs);
}
void otLogCritPlat(const char* format, ...) {
va_list args;
@ -28,38 +42,6 @@ void otLogCritPlat(const char* format, ...) {
va_end(args);
}
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);
}
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, ...) {
va_list args;
va_start(args, format);
__android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, args);
va_end(args);
}
void otDumpDebgPlat(const char* aText, const void* aData, uint16_t aDataLength) {
constexpr uint16_t kBufSize = 512;
char buf[kBufSize];