/* * Copyright (c) Facebook, Inc. and its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include namespace folly { namespace observer { namespace detail { template class ObserverCreatorContext; } template struct ObservableTraits { using element_type = typename std::remove_reference::type::element_type; static std::shared_ptr get(Observable& observable) { return observable.get(); } template static void subscribe(Observable& observable, F&& callback) { observable.subscribe(std::forward(callback)); } static void unsubscribe(Observable& observable) { observable.unsubscribe(); } }; template > class ObserverCreator { public: using T = typename Traits::element_type; template explicit ObserverCreator(Args&&... args); Observer getObserver() &&; private: using Context = detail::ObserverCreatorContext; class ContextPrimaryPtr; std::shared_ptr context_; }; } // namespace observer } // namespace folly #include