1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_ASH_COMPONENTS_DBUS_LORGNETTE_MANAGER_LORGNETTE_MANAGER_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_LORGNETTE_MANAGER_LORGNETTE_MANAGER_CLIENT_H_
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "chromeos/ash/components/dbus/lorgnette/lorgnette_service.pb.h"
#include "chromeos/dbus/common/dbus_callback.h"
#include "chromeos/dbus/common/dbus_client.h"
namespace ash {
// LorgnetteManagerClient is used to communicate with the lorgnette
// document scanning daemon.
class COMPONENT_EXPORT(LORGNETTE_MANAGER) LorgnetteManagerClient
: public chromeos::DBusClient {
public:
// Attributes provided to a scan request.
struct ScanProperties {
std::string mode; // Can be "Color", "Gray", or "Lineart".
int resolution_dpi = 0;
};
// Creates and initializes the global instance. |bus| must not be null.
static void Initialize(dbus::Bus* bus);
// Creates and initializes a fake global instance.
static void InitializeFake();
// Destroys the global instance if it has been initialized.
static void Shutdown();
// Returns the global instance if initialized. May return null.
static LorgnetteManagerClient* Get();
LorgnetteManagerClient(const LorgnetteManagerClient&) = delete;
LorgnetteManagerClient& operator=(const LorgnetteManagerClient&) = delete;
// Gets a list of scanners from the lorgnette manager.
virtual void ListScanners(
const std::string& client_id,
bool local_only,
bool preferred_only,
chromeos::DBusMethodCallback<lorgnette::ListScannersResponse>
callback) = 0;
// Gets the capabilities of the scanner corresponding to |device_name| and
// returns them using the provided |callback|.
virtual void GetScannerCapabilities(
const std::string& device_name,
chromeos::DBusMethodCallback<lorgnette::ScannerCapabilities>
callback) = 0;
// Opens the scanner described by |request| and returns the result using the
// provided |callback|.
virtual void OpenScanner(
const lorgnette::OpenScannerRequest& request,
chromeos::DBusMethodCallback<lorgnette::OpenScannerResponse>
callback) = 0;
// Closes the scanner described by |request| and returns the result using the
// provided |callback|.
virtual void CloseScanner(
const lorgnette::CloseScannerRequest& request,
chromeos::DBusMethodCallback<lorgnette::CloseScannerResponse>
callback) = 0;
// Sets the options as described by |request| and returns the result using the
// provided |callback|.
virtual void SetOptions(
const lorgnette::SetOptionsRequest& request,
chromeos::DBusMethodCallback<lorgnette::SetOptionsResponse> callback) = 0;
// Gets the config for the the scanner described by |request| and returns the
// result using the provided |callback|.
virtual void GetCurrentConfig(
const lorgnette::GetCurrentConfigRequest& request,
chromeos::DBusMethodCallback<lorgnette::GetCurrentConfigResponse>
callback) = 0;
// Starts a scan using information in |request| and returns the result using
// the provided |callback|.
virtual void StartPreparedScan(
const lorgnette::StartPreparedScanRequest& request,
chromeos::DBusMethodCallback<lorgnette::StartPreparedScanResponse>
callback) = 0;
// Request a scanned image using lorgnette's StartScan API. As each page is
// completed, calls |page_callback| with the page number and a string
// containing the image data. Calls |completion_callback| when the scan has
// completed. Image data will be stored in the .png format.
//
// If |progress_callback| is provided, it will be called as scan progress
// increases. The progress will be passed as a value from 0-100.
virtual void StartScan(
const std::string& device_name,
const lorgnette::ScanSettings& settings,
base::OnceCallback<void(lorgnette::ScanFailureMode)> completion_callback,
base::RepeatingCallback<void(std::string, uint32_t)> page_callback,
base::RepeatingCallback<void(uint32_t, uint32_t)> progress_callback) = 0;
// Reads scan data described by |request| and returns the results using the
// provided |callback|.
virtual void ReadScanData(
const lorgnette::ReadScanDataRequest& request,
chromeos::DBusMethodCallback<lorgnette::ReadScanDataResponse>
callback) = 0;
// Requests that lorgnette cancel the currently running scan job.
// When this function returns, that guarantees that cancelling has been
// requested, but the cancelled scan is not completely terminated until
// |cancel_callback| reports a successful result.
//
// Once CancelScan() returns, it is safe to request another scan, because
// lorgnette will prevent access to a device until the previous scan job has
// released it.
//
// This function makes the assumption that LorgnetteManagerClient only has one
// scan running at a time.
virtual void CancelScan(chromeos::VoidDBusMethodCallback cancel_callback) = 0;
// Cancels a scan specified by the JobHandle in |request| and returns the
// result using the provided |callback|.
virtual void CancelScan(
const lorgnette::CancelScanRequest& request,
chromeos::DBusMethodCallback<lorgnette::CancelScanResponse> callback) = 0;
// Starts a new scanner discovery session. A handle to the session is
// returned in the response. While the session is active, device update
// callbacks will be made.
virtual void StartScannerDiscovery(
const lorgnette::StartScannerDiscoveryRequest& request,
base::RepeatingCallback<void(lorgnette::ScannerListChangedSignal)>
signal_callback,
chromeos::DBusMethodCallback<lorgnette::StartScannerDiscoveryResponse>
response_callback) = 0;
// Stops an existing scanner discovery session.
virtual void StopScannerDiscovery(
const lorgnette::StopScannerDiscoveryRequest& request,
chromeos::DBusMethodCallback<lorgnette::StopScannerDiscoveryResponse>
callback) = 0;
protected:
friend class LorgnetteManagerClientTest;
// Initialize() should be used instead.
LorgnetteManagerClient();
~LorgnetteManagerClient() override;
};
} // namespace ash
#endif // CHROMEOS_ASH_COMPONENTS_DBUS_LORGNETTE_MANAGER_LORGNETTE_MANAGER_CLIENT_H_
|