UNPKG

2.05 kBtext/x-cView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <react/imagemanager/ImageResponse.h>
11#include <react/imagemanager/ImageResponseObserver.h>
12#include <react/imagemanager/ImageResponseObserverCoordinator.h>
13#include <react/imagemanager/primitives.h>
14
15namespace facebook {
16namespace react {
17
18/*
19 * Represents ongoing request for an image resource.
20 * The separate object must be constructed for every single separate
21 * image request. The object cannot be copied because it would make managing of
22 * event listeners hard and inefficient; the object can be moved though.
23 * Destroy to cancel the underlying request.
24 */
25class ImageRequest final {
26 public:
27 /*
28 * The exception which is thrown when `ImageRequest` is being deallocated
29 * if the future is not ready yet.
30 */
31 class ImageNoLongerNeededException;
32
33 /*
34 * The default constructor
35 */
36 ImageRequest(const ImageSource &imageSource);
37
38 /*
39 * The move constructor.
40 */
41 ImageRequest(ImageRequest &&other) noexcept;
42
43 /*
44 * `ImageRequest` does not support copying by design.
45 */
46 ImageRequest(const ImageRequest &other) = delete;
47
48 ~ImageRequest();
49
50 /**
51 * Set cancelation function.
52 */
53 void setCancelationFunction(std::function<void(void)> cancelationFunction);
54
55 /*
56 * Get observer coordinator.
57 */
58 const ImageResponseObserverCoordinator *getObserverCoordinator() const;
59
60 private:
61 /*
62 * Image source assosiated with the request.
63 */
64 ImageSource imageSource_;
65
66 /*
67 * Event coordinator associated with the reqest.
68 */
69 std::shared_ptr<const ImageResponseObserverCoordinator> coordinator_{};
70
71 /*
72 * Function we can call to cancel image request (see destructor).
73 */
74 std::function<void(void)> cancelRequest_;
75
76 /*
77 * Indicates that the object was moved and hence cannot be used anymore.
78 */
79 bool moved_{false};
80};
81
82} // namespace react
83} // namespace facebook