1 /*
2  * Copyright (C) 2016 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 MAIN_LOOP_H_
18 #define MAIN_LOOP_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "android-base/macros.h"
24 
25 #include "wifilogd/command_processor.h"
26 #include "wifilogd/os.h"
27 
28 namespace android {
29 namespace wifilogd {
30 
31 // The main event loop for wifilogd.
32 class MainLoop {
33  public:
34   explicit MainLoop(const std::string& socket_name);
35   MainLoop(const std::string& socket_name, std::unique_ptr<Os> os,
36            std::unique_ptr<CommandProcessor> command_processor);
37 
38   // Runs one iteration of the loop.
39   void RunOnce();
40 
41  private:
42   void ProcessError(Os::Errno err);
43 
44   std::unique_ptr<Os> os_;
45   std::unique_ptr<CommandProcessor> command_processor_;
46   // We use an int, rather than a unique_fd, because the file
47   // descriptor's lifetime is managed by init. (init creates
48   // the socket before forking our process.)
49   int sock_fd_;
50 
51   DISALLOW_COPY_AND_ASSIGN(MainLoop);
52 };
53 
54 }  // namespace wifilogd
55 }  // namespace android
56 
57 #endif  // MAIN_LOOP_H_
58