summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike J. Chen <mjchen@google.com>2011-06-23 15:00:30 -0700
committerMike J. Chen <mjchen@google.com>2011-06-23 18:59:45 -0700
commit17260b14682d4fe59dad3de2de8c9370e6ba9a71 (patch)
treee27c5d98b06c7b0b83702bd161b70a1a40b9dd44
parentec16b9d47cacb0d873ee0ff80c919f49215c0005 (diff)
downloadsystem_core-17260b14682d4fe59dad3de2de8c9370e6ba9a71.zip
system_core-17260b14682d4fe59dad3de2de8c9370e6ba9a71.tar.gz
system_core-17260b14682d4fe59dad3de2de8c9370e6ba9a71.tar.bz2
Cleanup NetlinkListener and NetlinkEvent
To make it easier to be compatible with older existing code, use default parameters instead of separate functions for setting. Also, reintroduce the const usage that was not in the original changes by Stan. Also fix some indent spacing. Change-Id: Ice9ec7f0d5c4a0673037e2e04a764d88a98f68eb Signed-off-by: Mike J. Chen <mjchen@google.com>
-rw-r--r--include/sysutils/NetlinkEvent.h4
-rw-r--r--include/sysutils/NetlinkListener.h3
-rw-r--r--libsysutils/src/NetlinkEvent.cpp17
-rw-r--r--libsysutils/src/NetlinkListener.cpp8
4 files changed, 15 insertions, 17 deletions
diff --git a/include/sysutils/NetlinkEvent.h b/include/sysutils/NetlinkEvent.h
index 1ee9849..25a56f7 100644
--- a/include/sysutils/NetlinkEvent.h
+++ b/include/sysutils/NetlinkEvent.h
@@ -16,6 +16,8 @@
#ifndef _NETLINKEVENT_H
#define _NETLINKEVENT_H
+#include <sysutils/NetlinkListener.h>
+
#define NL_PARAMS_MAX 32
class NetlinkEvent {
@@ -36,7 +38,7 @@ public:
NetlinkEvent();
virtual ~NetlinkEvent();
- bool decode(char *buffer, int size, int format);
+ bool decode(char *buffer, int size, int format = NetlinkListener::NETLINK_FORMAT_ASCII);
const char *findParam(const char *paramName);
const char *getSubsystem() { return mSubsystem; }
diff --git a/include/sysutils/NetlinkListener.h b/include/sysutils/NetlinkListener.h
index 1cf5f9f..de0fc3c 100644
--- a/include/sysutils/NetlinkListener.h
+++ b/include/sysutils/NetlinkListener.h
@@ -28,11 +28,12 @@ public:
static const int NETLINK_FORMAT_ASCII = 0;
static const int NETLINK_FORMAT_BINARY = 1;
- NetlinkListener(int socket, int format);
+ NetlinkListener(int socket, int format = NETLINK_FORMAT_ASCII);
virtual ~NetlinkListener() {}
protected:
virtual bool onDataAvailable(SocketClient *cli);
virtual void onEvent(NetlinkEvent *evt) = 0;
};
+
#endif
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index 65cfb4e..f2eb664 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -19,7 +19,6 @@
#define LOG_TAG "NetlinkEvent"
#include <cutils/log.h>
-#include <sysutils/NetlinkListener.h>
#include <sysutils/NetlinkEvent.h>
#include <sys/types.h>
@@ -69,7 +68,7 @@ void NetlinkEvent::dump() {
*/
bool NetlinkEvent::parseBinaryNetlinkMessage(char *buffer, int size) {
size_t sz = size;
- struct nlmsghdr *nh = (struct nlmsghdr *) buffer;
+ const struct nlmsghdr *nh = (struct nlmsghdr *) buffer;
while (NLMSG_OK(nh, sz) && (nh->nlmsg_type != NLMSG_DONE)) {
if (nh->nlmsg_type == RTM_NEWLINK) {
@@ -134,8 +133,8 @@ has_prefix(const char* str, const char* end, const char* prefix, size_t prefixle
* netlink socket.
*/
bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) {
- char *s = buffer;
- char *end;
+ const char *s = buffer;
+ const char *end;
int param_idx = 0;
int i;
int first = 1;
@@ -181,11 +180,11 @@ bool NetlinkEvent::parseAsciiNetlinkMessage(char *buffer, int size) {
}
bool NetlinkEvent::decode(char *buffer, int size, int format) {
- if (format == NetlinkListener::NETLINK_FORMAT_BINARY) {
- return parseBinaryNetlinkMessage(buffer, size);
- } else {
- return parseAsciiNetlinkMessage(buffer, size);
- }
+ if (format == NetlinkListener::NETLINK_FORMAT_BINARY) {
+ return parseBinaryNetlinkMessage(buffer, size);
+ } else {
+ return parseAsciiNetlinkMessage(buffer, size);
+ }
}
const char *NetlinkEvent::findParam(const char *paramName) {
diff --git a/libsysutils/src/NetlinkListener.cpp b/libsysutils/src/NetlinkListener.cpp
index c74e952..80d83c3 100644
--- a/libsysutils/src/NetlinkListener.cpp
+++ b/libsysutils/src/NetlinkListener.cpp
@@ -24,12 +24,10 @@
#include <cutils/log.h>
#include <cutils/uevent.h>
-#include <sysutils/NetlinkListener.h>
#include <sysutils/NetlinkEvent.h>
NetlinkListener::NetlinkListener(int socket, int format) :
- SocketListener(socket, false) {
- mFormat = format;
+ SocketListener(socket, false), mFormat(format) {
}
bool NetlinkListener::onDataAvailable(SocketClient *cli)
@@ -44,9 +42,7 @@ bool NetlinkListener::onDataAvailable(SocketClient *cli)
}
NetlinkEvent *evt = new NetlinkEvent();
- int err = evt->decode(mBuffer, count, mFormat);
-
- if (!err) {
+ if (!evt->decode(mBuffer, count, mFormat)) {
SLOGE("Error decoding NetlinkEvent");
} else {
onEvent(evt);