summaryrefslogtreecommitdiffstats
path: root/include/sysutils
diff options
context:
space:
mode:
authorSan Mehat <san@google.com>2009-05-08 11:15:53 -0700
committerSan Mehat <san@google.com>2009-05-10 09:26:42 -0700
commitfa644ffe944c01a9b00f8d7676d58394fabee285 (patch)
treea19968819547c4b515c463adb48106a8d01983aa /include/sysutils
parent1441e769b2767e212a3d905bee2fd3535b484ff2 (diff)
downloadsystem_core-fa644ffe944c01a9b00f8d7676d58394fabee285.zip
system_core-fa644ffe944c01a9b00f8d7676d58394fabee285.tar.gz
system_core-fa644ffe944c01a9b00f8d7676d58394fabee285.tar.bz2
libsysutils: Add multiple client support and fix some bugs
Diffstat (limited to 'include/sysutils')
-rw-r--r--include/sysutils/FrameworkClient.h21
-rw-r--r--include/sysutils/FrameworkCommand.h3
-rw-r--r--include/sysutils/FrameworkListener.h6
-rw-r--r--include/sysutils/FrameworkManager.h40
-rw-r--r--include/sysutils/NetlinkListener.h2
-rw-r--r--include/sysutils/SocketClient.h23
-rw-r--r--include/sysutils/SocketListener.h31
7 files changed, 74 insertions, 52 deletions
diff --git a/include/sysutils/FrameworkClient.h b/include/sysutils/FrameworkClient.h
new file mode 100644
index 0000000..1eb112a
--- /dev/null
+++ b/include/sysutils/FrameworkClient.h
@@ -0,0 +1,21 @@
+#ifndef _FRAMEWORK_CLIENT_H
+#define _FRAMEWORK_CLIENT_H
+
+#include "../../../frameworks/base/include/utils/List.h"
+
+#include <pthread.h>
+
+class FrameworkClient {
+ int mSocket;
+ pthread_mutex_t mWriteMutex;
+
+public:
+ FrameworkClient(int sock);
+ virtual ~FrameworkClient() {}
+
+ int sendMsg(char *msg);
+ int sendMsg(char *msg, char *data);
+};
+
+typedef android::List<FrameworkClient *> FrameworkClientCollection;
+#endif
diff --git a/include/sysutils/FrameworkCommand.h b/include/sysutils/FrameworkCommand.h
index 952e99a..5b50247 100644
--- a/include/sysutils/FrameworkCommand.h
+++ b/include/sysutils/FrameworkCommand.h
@@ -18,6 +18,7 @@
#include "../../../frameworks/base/include/utils/List.h"
+class SocketClient;
class FrameworkCommand {
private:
@@ -28,7 +29,7 @@ public:
FrameworkCommand(const char *cmd);
virtual ~FrameworkCommand() { }
- virtual int runCommand(char *data);
+ virtual int runCommand(SocketClient *c, char *data) = 0;
const char *getCommand() { return mCommand; }
};
diff --git a/include/sysutils/FrameworkListener.h b/include/sysutils/FrameworkListener.h
index 1454a6f..8a83c33 100644
--- a/include/sysutils/FrameworkListener.h
+++ b/include/sysutils/FrameworkListener.h
@@ -19,6 +19,8 @@
#include "SocketListener.h"
#include "FrameworkCommand.h"
+class SocketClient;
+
class FrameworkListener : public SocketListener {
private:
FrameworkCommandCollection *mCommands;
@@ -29,9 +31,9 @@ public:
protected:
void registerCmd(FrameworkCommand *cmd);
- virtual bool onDataAvailable(int socket);
+ virtual bool onDataAvailable(SocketClient *c);
private:
- void dispatchCommand(char *cmd);
+ void dispatchCommand(SocketClient *c, char *cmd);
};
#endif
diff --git a/include/sysutils/FrameworkManager.h b/include/sysutils/FrameworkManager.h
deleted file mode 100644
index 8a24d33..0000000
--- a/include/sysutils/FrameworkManager.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef _FRAMEWORKMANAGER_H
-#define _FRAMEWORKMANAGER_H
-
-#include <pthread.h>
-
-class FrameworkListener;
-
-class FrameworkManager {
- int mDoorbell; // Socket used to accept connections from framework
- int mFwSock; // Socket used to communicate with framework
- const char *mSocketName;
-
- FrameworkListener *mListener;
-
- pthread_mutex_t mWriteMutex;
-
-public:
- FrameworkManager(FrameworkListener *Listener);
- virtual ~FrameworkManager() {}
-
- int run();
- int sendMsg(char *msg);
- int sendMsg(char *msg, char *data);
-};
-#endif
diff --git a/include/sysutils/NetlinkListener.h b/include/sysutils/NetlinkListener.h
index 8ac811c..6dcc005 100644
--- a/include/sysutils/NetlinkListener.h
+++ b/include/sysutils/NetlinkListener.h
@@ -27,6 +27,6 @@ public:
NetlinkListener(int socket);
virtual ~NetlinkListener() {}
protected:
- virtual bool onDataAvailable(int socket);
+ virtual bool onDataAvailable(SocketClient *cli);
};
#endif
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h
new file mode 100644
index 0000000..39ec7ae
--- /dev/null
+++ b/include/sysutils/SocketClient.h
@@ -0,0 +1,23 @@
+#ifndef _SOCKET_CLIENT_H
+#define _SOCKET_CLIENT_H
+
+#include "../../../frameworks/base/include/utils/List.h"
+
+#include <pthread.h>
+
+class SocketClient {
+ int mSocket;
+ pthread_mutex_t mWriteMutex;
+
+public:
+ SocketClient(int sock);
+ virtual ~SocketClient() {}
+
+ int getSocket() { return mSocket; }
+
+ int sendMsg(char *msg);
+ int sendMsg(char *msg, char *data);
+};
+
+typedef android::List<SocketClient *> SocketClientCollection;
+#endif
diff --git a/include/sysutils/SocketListener.h b/include/sysutils/SocketListener.h
index f079dba..be97421 100644
--- a/include/sysutils/SocketListener.h
+++ b/include/sysutils/SocketListener.h
@@ -16,20 +16,35 @@
#ifndef _SOCKETLISTENER_H
#define _SOCKETLISTENER_H
+#include <pthread.h>
+
+#include <sysutils/SocketClient.h>
+
class SocketListener {
- int mSock;
- int mCsock;
- int mAcceptClients;
- const char *mSocketName;
+ int mSock;
+ const char *mSocketName;
+ SocketClientCollection *mClients;
+ pthread_mutex_t mClientsLock;
+ bool mListen;
+ int mCtrlPipe[2];
+ pthread_t mThread;
public:
- SocketListener(const char *socketName, bool acceptClients);
- SocketListener(int socketFd, bool acceptClients);
+ SocketListener(const char *socketNames, bool listen);
+ SocketListener(int socketFd, bool listen);
virtual ~SocketListener() {}
- virtual int run();
+ int startListener();
+ int stopListener();
+
+ void sendBroadcast(char *msg);
+ void sendBroadcast(char *msg, char *data);
protected:
- virtual bool onDataAvailable(int socket);
+ virtual bool onDataAvailable(SocketClient *c) = 0;
+
+private:
+ static void *threadStart(void *obj);
+ void runListener();
};
#endif