blob: c5a4b48e579c01899a2973c005045c6258ac38e5 [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:
42 std::unique_ptr<Os> os_;
43 std::unique_ptr<CommandProcessor> command_processor_;
44 // We use an int, rather than a unique_fd, because the file
45 // descriptor's lifetime is managed by init. (init creates
46 // the socket before forking our process.)
47 int sock_fd_;
48
49 DISALLOW_COPY_AND_ASSIGN(MainLoop);
50};
51
52} // namespace wifilogd
53} // namespace android
54
55#endif // MAIN_LOOP_H_