Files
react-native/ReactCommon/fabric/imagemanager/ImageResponseObserverCoordinator.h
T
zhongwuzw 25a58d7bbb Consolidate shared_mutex with better::shared_mutex (#24075)
Summary:
Replace `folly::SharedMutex` with `better::shared_mutex`, consolidate the shared_mutex.
cc. shergin .

[General] [Changed] - Consolidate shared_mutex with better::shared_mutex
Pull Request resolved: https://github.com/facebook/react-native/pull/24075

Differential Revision: D14559213

Pulled By: shergin

fbshipit-source-id: 934c7cd7db9ce60031d6b007faeebb353860268f
2019-03-21 00:18:33 -07:00

91 lines
2.1 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <react/imagemanager/ImageResponse.h>
#include <react/imagemanager/ImageResponseObserver.h>
#include <better/mutex.h>
#include <vector>
namespace facebook {
namespace react {
/*
* The ImageResponseObserverCoordinator receives events and completed image
* data from native image loaders and sends events to any observers attached
* to the coordinator. The Coordinator also keeps track of response status
* and caches completed images.
*/
class ImageResponseObserverCoordinator {
public:
/*
* Default constructor.
*/
ImageResponseObserverCoordinator();
/*
* Default destructor.
*/
~ImageResponseObserverCoordinator();
/*
* Interested parties may observe the image response.
*/
void addObserver(ImageResponseObserver *observer) const;
/*
* Interested parties may stop observing the image response.
*/
void removeObserver(ImageResponseObserver *observer) const;
/*
* Platform-specific image loader will call this method with progress updates.
*/
void nativeImageResponseProgress(float) const;
/*
* Platform-specific image loader will call this method with a completed image
* response.
*/
void nativeImageResponseComplete(const ImageResponse &imageResponse) const;
/*
* Platform-specific image loader will call this method in case of any
* failures.
*/
void nativeImageResponseFailed() const;
private:
/*
* List of observers.
* Mutable: protected by mutex_.
*/
mutable std::vector<ImageResponseObserver *> observers_;
/*
* Current status of image loading.
* Mutable: protected by mutex_.
*/
mutable ImageResponse::Status status_;
/*
* Cache image data.
* Mutable: protected by mutex_.
*/
mutable std::shared_ptr<void> imageData_{};
/*
* Observer and data mutex.
*/
mutable better::shared_mutex mutex_;
};
} // namespace react
} // namespace facebook