NetlinkEvent.h revision 17260b14682d4fe59dad3de2de8c9370e6ba9a71
1ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate/*
2ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * Copyright (C) 2008 The Android Open Source Project
3ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *
4ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * Licensed under the Apache License, Version 2.0 (the "License");
5ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * you may not use this file except in compliance with the License.
6ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * You may obtain a copy of the License at
7ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *
8ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *      http://www.apache.org/licenses/LICENSE-2.0
9ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate *
10ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * Unless required by applicable law or agreed to in writing, software
11ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * distributed under the License is distributed on an "AS IS" BASIS,
12ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * See the License for the specific language governing permissions and
14ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate * limitations under the License.
15ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate */
16ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate#ifndef _NETLINKEVENT_H
17ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate#define _NETLINKEVENT_H
18ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
194528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tate#include <sysutils/NetlinkListener.h>
204528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tate
214528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tate#define NL_PARAMS_MAX 32
224528186e0d65fc68ef0dd1941aa2ac8aefcd55a3Christopher Tate
23ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tateclass NetlinkEvent {
24ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    int  mSeq;
25ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    char *mPath;
26284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate    int  mAction;
27284f1bb4daf77f7e6b688c0936dd4a31ec2e7c74Christopher Tate    char *mSubsystem;
28ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    char *mParams[NL_PARAMS_MAX];
29ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
30ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tatepublic:
31ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    const static int NlActionUnknown;
32ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    const static int NlActionAdd;
33ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    const static int NlActionRemove;
34ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    const static int NlActionChange;
35ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    const static int NlActionLinkDown;
36ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    const static int NlActionLinkUp;
37ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
38ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    NetlinkEvent();
39ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    virtual ~NetlinkEvent();
40ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
41f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate    bool decode(char *buffer, int size, int format = NetlinkListener::NETLINK_FORMAT_ASCII);
42f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate    const char *findParam(const char *paramName);
43f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
44f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate    const char *getSubsystem() { return mSubsystem; }
45f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate    int getAction() { return mAction; }
46f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
47ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    void dump();
48f68eb500f99361541049e09eb7f9ddd6f4ef4efaChristopher Tate
49ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate protected:
50ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    bool parseBinaryNetlinkMessage(char *buffer, int size);
51ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate    bool parseAsciiNetlinkMessage(char *buffer, int size);
52ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate};
53ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate
54ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate#endif
55ace7f094bf07bbd90cb998b9462e4f2d101a498cChristopher Tate