Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: tools/android/forwarder2/daemon.h

Issue 11360248: Use the new forwarder2's Daemon implementation in device_forwarder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address David's comments Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/forwarder.py ('k') | tools/android/forwarder2/daemon.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/forwarder2/daemon.h
diff --git a/tools/android/forwarder2/daemon.h b/tools/android/forwarder2/daemon.h
index f3654e0c199707ccfdf0905852006759f7b9cf14..84f646df14d7cab87cca733c930176c172931398 100644
--- a/tools/android/forwarder2/daemon.h
+++ b/tools/android/forwarder2/daemon.h
@@ -7,28 +7,73 @@
#include <string>
-#include "base/at_exit.h"
#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
namespace forwarder2 {
+class Socket;
+
+// Provides a way to spawn a daemon and communicate with it.
class Daemon {
public:
+ // Callback used by the daemon to shutdown properly. See pipe_notifier.h for
+ // more details.
+ typedef int (*GetExitNotifierFDCallback)();
+
+ class ClientDelegate {
+ public:
+ virtual ~ClientDelegate() {}
+
+ // Called after the daemon is ready to receive commands.
+ virtual void OnDaemonReady(Socket* daemon_socket) = 0;
+ };
+
+ class ServerDelegate {
+ public:
+ virtual ~ServerDelegate() {}
+
+ // Called after the daemon bound its Unix Domain Socket. This can be used to
+ // setup signal handlers or perform global initialization.
+ virtual void Init() = 0;
+
+ virtual void OnClientConnected(scoped_ptr<Socket> client_socket) = 0;
+
+ virtual void OnServerExited() = 0;
+ };
+
// |pid_file_path| is the file path to which the daemon's PID will be written.
- // Note that a lock on the file is also acquired to guarantee that a single
- // instance of daemon is running.
- explicit Daemon(const std::string& pid_file_path);
+ // |identifier| should be a unique string identifier. It is used to
+ // bind/connect the underlying Unix Domain Socket.
+ // Note that this class does not take ownership of |client_delegate| and
+ // |server_delegate|.
+ Daemon(const std::string& log_file_path,
+ const std::string& pid_file_path,
+ const std::string& identifier,
+ ClientDelegate* client_delegate,
+ ServerDelegate* server_delegate,
+ GetExitNotifierFDCallback get_exit_fd_callback);
- // Returns whether the daemon was successfully spawned. Use |is_daemon| to
- // distinguish the parent from the child (daemon) process.
- bool Spawn(bool* is_daemon);
+ ~Daemon();
- // Kills the daemon and blocks until it exited.
+ // Returns whether the daemon was successfully spawned. Note that this does
+ // not necessarily mean that the current process was forked in case the daemon
+ // is already running.
+ bool SpawnIfNeeded();
+
+ // Kills the daemon and blocks until it exited. Returns whether it succeeded.
bool Kill();
private:
+ class PIDFile;
+
+ const std::string log_file_path_;
const std::string pid_file_path_;
- base::AtExitManager at_exit_manager;
+ const std::string identifier_;
+ ClientDelegate* const client_delegate_;
+ ServerDelegate* const server_delegate_;
+ const GetExitNotifierFDCallback get_exit_fd_callback_;
+ scoped_ptr<PIDFile> pid_file_;
DISALLOW_COPY_AND_ASSIGN(Daemon);
};
« no previous file with comments | « build/android/pylib/forwarder.py ('k') | tools/android/forwarder2/daemon.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698