summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'include/sysutils')
l---------include/sysutils1
-rw-r--r--include/sysutils/FrameworkClient.h21
-rw-r--r--include/sysutils/FrameworkCommand.h38
-rw-r--r--include/sysutils/FrameworkListener.h51
-rw-r--r--include/sysutils/List.h334
-rw-r--r--include/sysutils/NetlinkEvent.h69
-rw-r--r--include/sysutils/NetlinkListener.h49
-rw-r--r--include/sysutils/ServiceManager.h30
-rw-r--r--include/sysutils/SocketClient.h88
-rw-r--r--include/sysutils/SocketClientCommand.h27
-rw-r--r--include/sysutils/SocketListener.h59
11 files changed, 1 insertions, 766 deletions
diff --git a/include/sysutils b/include/sysutils
new file mode 120000
index 000000000..1c8e85bd1
--- /dev/null
+++ b/include/sysutils
@@ -0,0 +1 @@
../libsysutils/include/sysutils/ \ No newline at end of file
diff --git a/include/sysutils/FrameworkClient.h b/include/sysutils/FrameworkClient.h
deleted file mode 100644
index 4a3f0de0e..000000000
--- a/include/sysutils/FrameworkClient.h
+++ /dev/null
@@ -1,21 +0,0 @@
1#ifndef _FRAMEWORK_CLIENT_H
2#define _FRAMEWORK_CLIENT_H
3
4#include "List.h"
5
6#include <pthread.h>
7
8class FrameworkClient {
9 int mSocket;
10 pthread_mutex_t mWriteMutex;
11
12public:
13 FrameworkClient(int sock);
14 virtual ~FrameworkClient() {}
15
16 int sendMsg(const char *msg);
17 int sendMsg(const char *msg, const char *data);
18};
19
20typedef android::sysutils::List<FrameworkClient *> FrameworkClientCollection;
21#endif
diff --git a/include/sysutils/FrameworkCommand.h b/include/sysutils/FrameworkCommand.h
deleted file mode 100644
index 3e6264bbd..000000000
--- a/include/sysutils/FrameworkCommand.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef __FRAMEWORK_CMD_HANDLER_H
17#define __FRAMEWORK_CMD_HANDLER_H
18
19#include "List.h"
20
21class SocketClient;
22
23class FrameworkCommand {
24private:
25 const char *mCommand;
26
27public:
28
29 FrameworkCommand(const char *cmd);
30 virtual ~FrameworkCommand() { }
31
32 virtual int runCommand(SocketClient *c, int argc, char **argv) = 0;
33
34 const char *getCommand() { return mCommand; }
35};
36
37typedef android::sysutils::List<FrameworkCommand *> FrameworkCommandCollection;
38#endif
diff --git a/include/sysutils/FrameworkListener.h b/include/sysutils/FrameworkListener.h
deleted file mode 100644
index 2137069fb..000000000
--- a/include/sysutils/FrameworkListener.h
+++ /dev/null
@@ -1,51 +0,0 @@
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _FRAMEWORKSOCKETLISTENER_H
17#define _FRAMEWORKSOCKETLISTENER_H
18
19#include "SocketListener.h"
20#include "FrameworkCommand.h"
21
22class SocketClient;
23
24class FrameworkListener : public SocketListener {
25public:
26 static const int CMD_ARGS_MAX = 26;
27
28 /* 1 out of errorRate will be dropped */
29 int errorRate;
30
31private:
32 int mCommandCount;
33 bool mWithSeq;
34 FrameworkCommandCollection *mCommands;
35 bool mSkipToNextNullByte;
36
37public:
38 FrameworkListener(const char *socketName);
39 FrameworkListener(const char *socketName, bool withSeq);
40 FrameworkListener(int sock);
41 virtual ~FrameworkListener() {}
42
43protected:
44 void registerCmd(FrameworkCommand *cmd);
45 virtual bool onDataAvailable(SocketClient *c);
46
47private:
48 void dispatchCommand(SocketClient *c, char *data);
49 void init(const char *socketName, bool withSeq);
50};
51#endif
diff --git a/include/sysutils/List.h b/include/sysutils/List.h
deleted file mode 100644
index 31f7b37c1..000000000
--- a/include/sysutils/List.h
+++ /dev/null
@@ -1,334 +0,0 @@
1/*
2 * Copyright (C) 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//
18// Templated list class. Normally we'd use STL, but we don't have that.
19// This class mimics STL's interfaces.
20//
21// Objects are copied into the list with the '=' operator or with copy-
22// construction, so if the compiler's auto-generated versions won't work for
23// you, define your own.
24//
25// The only class you want to use from here is "List".
26//
27#ifndef _SYSUTILS_LIST_H
28#define _SYSUTILS_LIST_H
29
30#include <stddef.h>
31#include <stdint.h>
32
33namespace android {
34namespace sysutils {
35
36/*
37 * Doubly-linked list. Instantiate with "List<MyClass> myList".
38 *
39 * Objects added to the list are copied using the assignment operator,
40 * so this must be defined.
41 */
42template<typename T>
43class List
44{
45protected:
46 /*
47 * One element in the list.
48 */
49 class _Node {
50 public:
51 explicit _Node(const T& val) : mVal(val) {}
52 ~_Node() {}
53 inline T& getRef() { return mVal; }
54 inline const T& getRef() const { return mVal; }
55 inline _Node* getPrev() const { return mpPrev; }
56 inline _Node* getNext() const { return mpNext; }
57 inline void setVal(const T& val) { mVal = val; }
58 inline void setPrev(_Node* ptr) { mpPrev = ptr; }
59 inline void setNext(_Node* ptr) { mpNext = ptr; }
60 private:
61 friend class List;
62 friend class _ListIterator;
63 T mVal;
64 _Node* mpPrev;
65 _Node* mpNext;
66 };
67
68 /*
69 * Iterator for walking through the list.
70 */
71
72 template <typename TYPE>
73 struct CONST_ITERATOR {
74 typedef _Node const * NodePtr;
75 typedef const TYPE Type;
76 };
77
78 template <typename TYPE>
79 struct NON_CONST_ITERATOR {
80 typedef _Node* NodePtr;
81 typedef TYPE Type;
82 };
83
84 template<
85 typename U,
86 template <class> class Constness
87 >
88 class _ListIterator {
89 typedef _ListIterator<U, Constness> _Iter;
90 typedef typename Constness<U>::NodePtr _NodePtr;
91 typedef typename Constness<U>::Type _Type;
92
93 explicit _ListIterator(_NodePtr ptr) : mpNode(ptr) {}
94
95 public:
96 _ListIterator() {}
97 _ListIterator(const _Iter& rhs) : mpNode(rhs.mpNode) {}
98 ~_ListIterator() {}
99
100 // this will handle conversions from iterator to const_iterator
101 // (and also all convertible iterators)
102 // Here, in this implementation, the iterators can be converted
103 // if the nodes can be converted
104 template<typename V> explicit
105 _ListIterator(const V& rhs) : mpNode(rhs.mpNode) {}
106
107
108 /*
109 * Dereference operator. Used to get at the juicy insides.
110 */
111 _Type& operator*() const { return mpNode->getRef(); }
112 _Type* operator->() const { return &(mpNode->getRef()); }
113
114 /*
115 * Iterator comparison.
116 */
117 inline bool operator==(const _Iter& right) const {
118 return mpNode == right.mpNode; }
119
120 inline bool operator!=(const _Iter& right) const {
121 return mpNode != right.mpNode; }
122
123 /*
124 * handle comparisons between iterator and const_iterator
125 */
126 template<typename OTHER>
127 inline bool operator==(const OTHER& right) const {
128 return mpNode == right.mpNode; }
129
130 template<typename OTHER>
131 inline bool operator!=(const OTHER& right) const {
132 return mpNode != right.mpNode; }
133
134 /*
135 * Incr/decr, used to move through the list.
136 */
137 inline _Iter& operator++() { // pre-increment
138 mpNode = mpNode->getNext();
139 return *this;
140 }
141 const _Iter operator++(int) { // post-increment
142 _Iter tmp(*this);
143 mpNode = mpNode->getNext();
144 return tmp;
145 }
146 inline _Iter& operator--() { // pre-increment
147 mpNode = mpNode->getPrev();
148 return *this;
149 }
150 const _Iter operator--(int) { // post-increment
151 _Iter tmp(*this);
152 mpNode = mpNode->getPrev();
153 return tmp;
154 }
155
156 inline _NodePtr getNode() const { return mpNode; }
157
158 _NodePtr mpNode; /* should be private, but older gcc fails */
159 private:
160 friend class List;
161 };
162
163public:
164 List() {
165 prep();
166 }
167 List(const List<T>& src) { // copy-constructor
168 prep();
169 insert(begin(), src.begin(), src.end());
170 }
171 virtual ~List() {
172 clear();
173 delete[] (unsigned char*) mpMiddle;
174 }
175
176 typedef _ListIterator<T, NON_CONST_ITERATOR> iterator;
177 typedef _ListIterator<T, CONST_ITERATOR> const_iterator;
178
179 List<T>& operator=(const List<T>& right);
180
181 /* returns true if the list is empty */
182 inline bool empty() const { return mpMiddle->getNext() == mpMiddle; }
183
184 /* return #of elements in list */
185 size_t size() const {
186 return size_t(distance(begin(), end()));
187 }
188
189 /*
190 * Return the first element or one past the last element. The
191 * _Node* we're returning is converted to an "iterator" by a
192 * constructor in _ListIterator.
193 */
194 inline iterator begin() {
195 return iterator(mpMiddle->getNext());
196 }
197 inline const_iterator begin() const {
198 return const_iterator(const_cast<_Node const*>(mpMiddle->getNext()));
199 }
200 inline iterator end() {
201 return iterator(mpMiddle);
202 }
203 inline const_iterator end() const {
204 return const_iterator(const_cast<_Node const*>(mpMiddle));
205 }
206
207 /* add the object to the head or tail of the list */
208 void push_front(const T& val) { insert(begin(), val); }
209 void push_back(const T& val) { insert(end(), val); }
210
211 /* insert before the current node; returns iterator at new node */
212 iterator insert(iterator posn, const T& val)
213 {
214 _Node* newNode = new _Node(val); // alloc & copy-construct
215 newNode->setNext(posn.getNode());
216 newNode->setPrev(posn.getNode()->getPrev());
217 posn.getNode()->getPrev()->setNext(newNode);
218 posn.getNode()->setPrev(newNode);
219 return iterator(newNode);
220 }
221
222 /* insert a range of elements before the current node */
223 void insert(iterator posn, const_iterator first, const_iterator last) {
224 for ( ; first != last; ++first)
225 insert(posn, *first);
226 }
227
228 /* remove one entry; returns iterator at next node */
229 iterator erase(iterator posn) {
230 _Node* pNext = posn.getNode()->getNext();
231 _Node* pPrev = posn.getNode()->getPrev();
232 pPrev->setNext(pNext);
233 pNext->setPrev(pPrev);
234 delete posn.getNode();
235 return iterator(pNext);
236 }
237
238 /* remove a range of elements */
239 iterator erase(iterator first, iterator last) {
240 while (first != last)
241 erase(first++); // don't erase than incr later!
242 return iterator(last);
243 }
244
245 /* remove all contents of the list */
246 void clear() {
247 _Node* pCurrent = mpMiddle->getNext();
248 _Node* pNext;
249
250 while (pCurrent != mpMiddle) {
251 pNext = pCurrent->getNext();
252 delete pCurrent;
253 pCurrent = pNext;
254 }
255 mpMiddle->setPrev(mpMiddle);
256 mpMiddle->setNext(mpMiddle);
257 }
258
259 /*
260 * Measure the distance between two iterators. On exist, "first"
261 * will be equal to "last". The iterators must refer to the same
262 * list.
263 *
264 * FIXME: This is actually a generic iterator function. It should be a
265 * template function at the top-level with specializations for things like
266 * vector<>, which can just do pointer math). Here we limit it to
267 * _ListIterator of the same type but different constness.
268 */
269 template<
270 typename U,
271 template <class> class CL,
272 template <class> class CR
273 >
274 ptrdiff_t distance(
275 _ListIterator<U, CL> first, _ListIterator<U, CR> last) const
276 {
277 ptrdiff_t count = 0;
278 while (first != last) {
279 ++first;
280 ++count;
281 }
282 return count;
283 }
284
285private:
286 /*
287 * I want a _Node but don't need it to hold valid data. More
288 * to the point, I don't want T's constructor to fire, since it
289 * might have side-effects or require arguments. So, we do this
290 * slightly uncouth storage alloc.
291 */
292 void prep() {
293 mpMiddle = (_Node*) new unsigned char[sizeof(_Node)];
294 mpMiddle->setPrev(mpMiddle);
295 mpMiddle->setNext(mpMiddle);
296 }
297
298 /*
299 * This node plays the role of "pointer to head" and "pointer to tail".
300 * It sits in the middle of a circular list of nodes. The iterator
301 * runs around the circle until it encounters this one.
302 */
303 _Node* mpMiddle;
304};
305
306/*
307 * Assignment operator.
308 *
309 * The simplest way to do this would be to clear out the target list and
310 * fill it with the source. However, we can speed things along by
311 * re-using existing elements.
312 */
313template<class T>
314List<T>& List<T>::operator=(const List<T>& right)
315{
316 if (this == &right)
317 return *this; // self-assignment
318 iterator firstDst = begin();
319 iterator lastDst = end();
320 const_iterator firstSrc = right.begin();
321 const_iterator lastSrc = right.end();
322 while (firstSrc != lastSrc && firstDst != lastDst)
323 *firstDst++ = *firstSrc++;
324 if (firstSrc == lastSrc) // ran out of elements in source?
325 erase(firstDst, lastDst); // yes, erase any extras
326 else
327 insert(lastDst, firstSrc, lastSrc); // copy remaining over
328 return *this;
329}
330
331}; // namespace sysutils
332}; // namespace android
333
334#endif // _SYSUTILS_LIST_H
diff --git a/include/sysutils/NetlinkEvent.h b/include/sysutils/NetlinkEvent.h
deleted file mode 100644
index b80f3ea44..000000000
--- a/include/sysutils/NetlinkEvent.h
+++ /dev/null
@@ -1,69 +0,0 @@
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _NETLINKEVENT_H
17#define _NETLINKEVENT_H
18
19#include <sysutils/NetlinkListener.h>
20
21#define NL_PARAMS_MAX 32
22
23class NetlinkEvent {
24public:
25 enum class Action {
26 kUnknown = 0,
27 kAdd = 1,
28 kRemove = 2,
29 kChange = 3,
30 kLinkUp = 4,
31 kLinkDown = 5,
32 kAddressUpdated = 6,
33 kAddressRemoved = 7,
34 kRdnss = 8,
35 kRouteUpdated = 9,
36 kRouteRemoved = 10,
37 };
38
39private:
40 int mSeq;
41 char *mPath;
42 Action mAction;
43 char *mSubsystem;
44 char *mParams[NL_PARAMS_MAX];
45
46public:
47 NetlinkEvent();
48 virtual ~NetlinkEvent();
49
50 bool decode(char *buffer, int size, int format = NetlinkListener::NETLINK_FORMAT_ASCII);
51 const char *findParam(const char *paramName);
52
53 const char *getSubsystem() { return mSubsystem; }
54 Action getAction() { return mAction; }
55
56 void dump();
57
58 protected:
59 bool parseBinaryNetlinkMessage(char *buffer, int size);
60 bool parseAsciiNetlinkMessage(char *buffer, int size);
61 bool parseIfInfoMessage(const struct nlmsghdr *nh);
62 bool parseIfAddrMessage(const struct nlmsghdr *nh);
63 bool parseUlogPacketMessage(const struct nlmsghdr *nh);
64 bool parseNfPacketMessage(struct nlmsghdr *nh);
65 bool parseRtMessage(const struct nlmsghdr *nh);
66 bool parseNdUserOptMessage(const struct nlmsghdr *nh);
67};
68
69#endif
diff --git a/include/sysutils/NetlinkListener.h b/include/sysutils/NetlinkListener.h
deleted file mode 100644
index 82465d697..000000000
--- a/include/sysutils/NetlinkListener.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _NETLINKLISTENER_H
17#define _NETLINKLISTENER_H
18
19#include "SocketListener.h"
20
21class NetlinkEvent;
22
23class NetlinkListener : public SocketListener {
24 char mBuffer[64 * 1024] __attribute__((aligned(4)));
25 int mFormat;
26
27public:
28 static const int NETLINK_FORMAT_ASCII = 0;
29 static const int NETLINK_FORMAT_BINARY = 1;
30 static const int NETLINK_FORMAT_BINARY_UNICAST = 2;
31
32#if 1
33 /* temporary version until we can get Motorola to update their
34 * ril.so. Their prebuilt ril.so is using this private class
35 * so changing the NetlinkListener() constructor breaks their ril.
36 */
37 NetlinkListener(int socket);
38 NetlinkListener(int socket, int format);
39#else
40 NetlinkListener(int socket, int format = NETLINK_FORMAT_ASCII);
41#endif
42 virtual ~NetlinkListener() {}
43
44protected:
45 virtual bool onDataAvailable(SocketClient *cli);
46 virtual void onEvent(NetlinkEvent *evt) = 0;
47};
48
49#endif
diff --git a/include/sysutils/ServiceManager.h b/include/sysutils/ServiceManager.h
deleted file mode 100644
index c31dd8f22..000000000
--- a/include/sysutils/ServiceManager.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _SERVICE_MANAGER_H
18#define _SERVICE_MANAGER_H
19
20class ServiceManager {
21public:
22 ServiceManager();
23 virtual ~ServiceManager() {}
24
25 int start(const char *name);
26 int stop(const char *name);
27 bool isRunning(const char *name);
28};
29
30#endif
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h
deleted file mode 100644
index 1004f0611..000000000
--- a/include/sysutils/SocketClient.h
+++ /dev/null
@@ -1,88 +0,0 @@
1#ifndef _SOCKET_CLIENT_H
2#define _SOCKET_CLIENT_H
3
4#include "List.h"
5
6#include <pthread.h>
7#include <cutils/atomic.h>
8#include <sys/types.h>
9#include <sys/uio.h>
10
11class SocketClient {
12 int mSocket;
13 bool mSocketOwned;
14 pthread_mutex_t mWriteMutex;
15
16 // Peer process ID
17 pid_t mPid;
18
19 // Peer user ID
20 uid_t mUid;
21
22 // Peer group ID
23 gid_t mGid;
24
25 // Reference count (starts at 1)
26 pthread_mutex_t mRefCountMutex;
27 int mRefCount;
28
29 int mCmdNum;
30
31 bool mUseCmdNum;
32
33public:
34 SocketClient(int sock, bool owned);
35 SocketClient(int sock, bool owned, bool useCmdNum);
36 virtual ~SocketClient();
37
38 int getSocket() { return mSocket; }
39 pid_t getPid() const { return mPid; }
40 uid_t getUid() const { return mUid; }
41 gid_t getGid() const { return mGid; }
42 void setCmdNum(int cmdNum) {
43 android_atomic_release_store(cmdNum, &mCmdNum);
44 }
45 int getCmdNum() { return mCmdNum; }
46
47 // Send null-terminated C strings:
48 int sendMsg(int code, const char *msg, bool addErrno);
49 int sendMsg(int code, const char *msg, bool addErrno, bool useCmdNum);
50 int sendMsg(const char *msg);
51
52 // Provides a mechanism to send a response code to the client.
53 // Sends the code and a null character.
54 int sendCode(int code);
55
56 // Provides a mechanism to send binary data to client.
57 // Sends the code and a null character, followed by 4 bytes of
58 // big-endian length, and the data.
59 int sendBinaryMsg(int code, const void *data, int len);
60
61 // Sending binary data:
62 int sendData(const void *data, int len);
63 // iovec contents not preserved through call
64 int sendDatav(struct iovec *iov, int iovcnt);
65
66 // Optional reference counting. Reference count starts at 1. If
67 // it's decremented to 0, it deletes itself.
68 // SocketListener creates a SocketClient (at refcount 1) and calls
69 // decRef() when it's done with the client.
70 void incRef();
71 bool decRef(); // returns true at 0 (but note: SocketClient already deleted)
72
73 // return a new string in quotes with '\\' and '\"' escaped for "my arg"
74 // transmissions
75 static char *quoteArg(const char *arg);
76
77private:
78 void init(int socket, bool owned, bool useCmdNum);
79
80 // Sending binary data. The caller should make sure this is protected
81 // from multiple threads entering simultaneously.
82 // returns 0 if successful, -1 if there is a 0 byte write or if any
83 // other error occurred (use errno to get the error)
84 int sendDataLockedv(struct iovec *iov, int iovcnt);
85};
86
87typedef android::sysutils::List<SocketClient *> SocketClientCollection;
88#endif
diff --git a/include/sysutils/SocketClientCommand.h b/include/sysutils/SocketClientCommand.h
deleted file mode 100644
index 746bc2587..000000000
--- a/include/sysutils/SocketClientCommand.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _SOCKETCLIENTCOMMAND_H
17#define _SOCKETCLIENTCOMMAND_H
18
19#include <sysutils/SocketClient.h>
20
21class SocketClientCommand {
22public:
23 virtual ~SocketClientCommand() { }
24 virtual void runSocketCommand(SocketClient *client) = 0;
25};
26
27#endif
diff --git a/include/sysutils/SocketListener.h b/include/sysutils/SocketListener.h
deleted file mode 100644
index bc93b8635..000000000
--- a/include/sysutils/SocketListener.h
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 * Copyright (C) 2008-2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef _SOCKETLISTENER_H
17#define _SOCKETLISTENER_H
18
19#include <pthread.h>
20
21#include <sysutils/SocketClient.h>
22#include "SocketClientCommand.h"
23
24class SocketListener {
25 bool mListen;
26 const char *mSocketName;
27 int mSock;
28 SocketClientCollection *mClients;
29 pthread_mutex_t mClientsLock;
30 int mCtrlPipe[2];
31 pthread_t mThread;
32 bool mUseCmdNum;
33
34public:
35 SocketListener(const char *socketName, bool listen);
36 SocketListener(const char *socketName, bool listen, bool useCmdNum);
37 SocketListener(int socketFd, bool listen);
38
39 virtual ~SocketListener();
40 int startListener();
41 int startListener(int backlog);
42 int stopListener();
43
44 void sendBroadcast(int code, const char *msg, bool addErrno);
45
46 void runOnEachSocket(SocketClientCommand *command);
47
48 bool release(SocketClient *c) { return release(c, true); }
49
50protected:
51 virtual bool onDataAvailable(SocketClient *c) = 0;
52
53private:
54 bool release(SocketClient *c, bool wakeup);
55 static void *threadStart(void *obj);
56 void runListener();
57 void init(const char *socketName, int socketFd, bool listen, bool useCmdNum);
58};
59#endif