blob: 53c42f807dbdff782f2fcd980bad8c66e96d1a27 [file] [log] [blame]
mukesh agrawal3b1d20a2016-10-27 14:19:12 -07001/*
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
28namespace android {
29namespace wifilogd {
30
31// The main event loop for wifilogd.
32class 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:
mukesh agrawalfd592212016-11-11 16:20:15 -080042 void ProcessError(Os::Errno err);
43
mukesh agrawal3b1d20a2016-10-27 14:19:12 -070044 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_