Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17260b14 authored by Mike J. Chen's avatar Mike J. Chen
Browse files

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: default avatarMike J. Chen <mjchen@google.com>
parent ec16b9d4
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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; }
+2 −1
Original line number Diff line number Diff line
@@ -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
+8 −9
Original line number Diff line number Diff line
@@ -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;
+2 −6
Original line number Diff line number Diff line
@@ -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);