blob: b07fdc2bfd9abc5cf2ddb480b95d6256fe0068d5 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fuchsia/camera3/cpp/fidl.h>
#include <fuchsia/sysmem/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/fpromise/result.h>
#include <lib/sys/cpp/component_context.h>
#include <stdio.h>
#include "src/camera/bin/factory/capture.h"
#include "src/lib/fsl/tasks/fd_waiter.h"
namespace camera {
// an interface for caller to provide access to resources
class WebUIControl {
virtual void RequestCaptureData(uint32_t stream_index, CaptureResponse callback) = 0;
// A Web UI for controlling camera-gym from the host
class WebUI {
// create a new WebUI.
static fpromise::result<std::unique_ptr<WebUI>, zx_status_t> Create(WebUIControl* control);
// start listening on a port (thread safe)
void PostListen(int port);
// listen for and handle new clients
void Listen(int port);
void ListenWaiter();
void OnListenReady(zx_status_t success, uint32_t events);
void HandleClient(FILE* fp);
// handle capture replies
void RequestCapture(FILE* fp, WriteFlags flags, bool saveToStorage);
// controller hooks, owned by the controller (WebUI is a view in MVC)
WebUIControl* control_;
async::Loop loop_;
int listen_sock_;
fsl::FDWaiter listen_waiter_;
bool is_bayer_ = false;
Crop crop_ = {0, 0, 0, 0};
bool is_center_ = false;
} // namespace camera