1 /*
2  * Copyright (C) 2020 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 #pragma once
18 
19 #include <map>
20 #include <memory>
21 
22 #include "common/libs/fs/shared_fd.h"
23 #include "host/frontend/webrtc/display_handler.h"
24 #include "host/frontend/webrtc/kernel_log_events_handler.h"
25 #include "host/frontend/webrtc/libdevice/camera_controller.h"
26 #include "host/frontend/webrtc/libdevice/connection_observer.h"
27 #include "host/frontend/webrtc/libdevice/lights_observer.h"
28 #include "host/frontend/webrtc/sensors_handler.h"
29 #include "host/libs/input_connector/input_connector.h"
30 
31 namespace cuttlefish {
32 
33 class CfConnectionObserverFactory
34     : public webrtc_streaming::ConnectionObserverFactory {
35  public:
36   CfConnectionObserverFactory(
37       InputConnector& input_connector,
38       KernelLogEventsHandler* kernel_log_events_handler,
39       std::shared_ptr<webrtc_streaming::LightsObserver> lights_observer);
40   ~CfConnectionObserverFactory() override = default;
41 
42   std::shared_ptr<webrtc_streaming::ConnectionObserver> CreateObserver()
43       override;
44 
45   void AddCustomActionServer(SharedFD custom_action_server_fd,
46                              const std::vector<std::string>& commands);
47 
48   void SetDisplayHandler(std::weak_ptr<DisplayHandler> display_handler);
49 
50   void SetCameraHandler(CameraController* controller);
51 
52  private:
53   InputConnector& input_connector_;
54   KernelLogEventsHandler* kernel_log_events_handler_;
55   std::map<std::string, SharedFD>
56       commands_to_custom_action_servers_;
57   std::weak_ptr<DisplayHandler> weak_display_handler_;
58   cuttlefish::CameraController* camera_controller_ = nullptr;
59   std::shared_ptr<webrtc_streaming::SensorsHandler> shared_sensors_handler_ =
60       std::make_shared<webrtc_streaming::SensorsHandler>();
61   std::shared_ptr<webrtc_streaming::LightsObserver> lights_observer_;
62 };
63 
64 }  // namespace cuttlefish
65