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

Side by Side Diff: service_manager.h

Issue 6508016: vpn-manager: Add l2tp/ipsec vpn manager (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vpn-manager.git@master
Patch Set: Add line combining Created 9 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef _VPN_MANAGER_SERVICE_MANAGER_H_
6 #define _VPN_MANAGER_SERVICE_MANAGER_H_
7
8 #include <string>
9
10 #include "base/file_path.h"
11 #include "gtest/gtest_prod.h" // for FRIEND_TEST
12
13 // Generic code to manage setting up and stopping a set of layered
14 // tunnel services. This object contains the code to manage a single
15 // layer. Services are meant to be started from outermost to innermost.
16 // Services are meant to be stopped from the innermost out. To
17 // stop the entire set of services, call Stop on the innermost.
18 // Services go from not-yet-started to started to in_running to
19 // was_stopped.
20 class ServiceManager {
21 public:
22 ServiceManager(const std::string& service_name);
23 virtual ~ServiceManager();
24
25 // Initialize directories used by services.
26 static void InitializeDirectories();
27
28 // Call to initiate this service. If starting fails immediately this
29 // returns false. If something fails after this returns, OnStopped
30 // will be called. Code outside of the service manager stack
31 // must only call Start on the outermost function.
32 virtual bool Start() = 0;
33
34 // Callback when this service has successfully started.
35 virtual void OnStarted();
36
37 // Call to stop this service. Must not be called on a separate
38 // thread from Start(). Code outside of the service manager stack
39 // must only call Stop on the innermost service. It is ok to
40 // stop an already stopped service.
41 virtual void Stop() = 0;
42
43 // Returns the maximum amount of time to wait before this call should be
44 // called again in milliseconds.
45 virtual int Poll() = 0;
46
47 // Process output from child process.
48 virtual void ProcessOutput() = 0;
49
50 // Returns if |pid| is a child process of this service.
51 virtual bool IsChild(pid_t pid) = 0;
52
53 // Callback when this service has stopped after having started
54 // successfully. |was_error| indicates if an error occurred.
55 virtual void OnStopped(bool was_error);
56
57 // Queries if this service is currently running.
58 bool is_running() {
59 return is_running_;
60 }
61
62 // Queries if this service was once running and is now stopped.
63 bool was_stopped() {
64 return was_stopped_;
65 }
66
67 // Set up layering between two service managers |outer| and |inner|.
68 static void SetLayerOrder(ServiceManager* outer,
69 ServiceManager* inner) {
70 outer->inner_service_ = inner;
71 inner->outer_service_ = outer;
72 }
73
74 const std::string& service_name() {
75 return service_name_;
76 }
77
78 // Repeat data from the given |fd| which is assumed to be ready
79 // and send it out to syslog, placing |prefix| before each line
80 // of output.
81 static void WriteFdToSyslog(int fd, const std::string& prefix,
82 std::string* partial_line);
83
84 protected:
85 friend class IpsecManagerTest;
86 friend class ServiceManagerTest;
87 FRIEND_TEST(ServiceManagerTest, InitializeDirectories);
88 FRIEND_TEST(ServiceManagerTest, OnStoppedFromFailure);
89 FRIEND_TEST(ServiceManagerTest, OnStoppedFromSuccess);
90
91 // Removes temporary directory.
92 static void DeleteTemp();
93
94 // Indicates if this service is currently running.
95 bool is_running_;
96
97 // Indicates if this service was running and is now stopped.
98 bool was_stopped_;
99
100 // Pointer to the next layer or NULL if innermost.
101 ServiceManager* inner_service_;
102
103 // Pointer to the outer layer or NULL if outermost.
104 ServiceManager* outer_service_;
105
106 // Name of this service.
107 std::string service_name_;
108
109 // Path to temporary directory on cryptohome.
110 static FilePath* temp_path_;
111 };
112
113 #endif // _VPN_MANAGER_SERVICE_MANAGER_H_
OLDNEW
« l2tp_manager.cc ('K') | « l2tpipsec_vpn.cc ('k') | service_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698