LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IpcServer.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2009-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef IPCSERVER_H
23 #define IPCSERVER_H
24 
25 #include "Common.h"
26 
27 #include <map>
28 #include <set>
29 #include <string>
30 
31 #include <PIpcServer.h>
32 
33 #include "Timer.h"
34 #include "ApplicationDescription.h"
35 
36 class IpcClientHost;
37 
38 class IpcServer : public PIpcServer
39 {
40 public:
41 
42  static IpcServer* instance();
43 
44  int launchNativeProcess(const std::string& appId, const char* path, char* const argv[], ApplicationDescription::Type appType, int requiredMemory = 0);
45  int launchWebAppProcess(const std::string& appId, const char* url, const char** argv);
46  void suspendProcess(int pid);
47  void resumeProcess(int pid);
48  void killProcess(int pid, bool notifyUser=false);
49  void processRemoved(int pid, bool doCleanup=true);
50  void addProcessToNukeList(int pid);
51  void ipcClientHostQuit(IpcClientHost* client);
52 
53 private:
54 
55  IpcServer();
56  ~IpcServer();
57 
58  virtual void clientConnected(int pid, const std::string& name, PIpcChannel* channel);
59 
60  bool nukeProcessTimer();
61  std::string appIdFromPid(int pid);
62  IpcClientHost* clientHostForAppId(const std::string& appId) const;
63 
64  static void childProcessDiedCallback(GPid pid, gint status, gpointer data);
65  void childProcessDied(GPid, gint status);
66 
67 private:
68 
69  typedef std::map<std::string, int> ProcessMap;
70  typedef std::set<int> ProcessSet;
71  typedef std::set<IpcClientHost*> ClientSet;
72 
73  ProcessMap m_nativeProcessMap;
74  ProcessMap m_webAppProcessMap;
75  ProcessSet m_nukeSet;
76  ClientSet m_clientHostSet;
77 
78  Timer<IpcServer> m_nukeProcessTimer;
79 };
80 
81 #endif /* IPCSERVER_H */