180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
480922886Sopenharmony_ci * you may not use this file except in compliance with the License.
580922886Sopenharmony_ci * You may obtain a copy of the License at
680922886Sopenharmony_ci *
780922886Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
880922886Sopenharmony_ci *
980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1280922886Sopenharmony_ci * See the License for the specific language governing permissions and
1380922886Sopenharmony_ci * limitations under the License.
1480922886Sopenharmony_ci */
1580922886Sopenharmony_ci
1680922886Sopenharmony_ci#ifndef AVSESSION_DISTRIBUTEDOBJECT_ADAPTER_H
1780922886Sopenharmony_ci#define AVSESSION_DISTRIBUTEDOBJECT_ADAPTER_H
1880922886Sopenharmony_ci
1980922886Sopenharmony_ci#include "distributed_objectstore.h"
2080922886Sopenharmony_ci#include "avmeta_data.h"
2180922886Sopenharmony_ci#include "avmedia_description.h"
2280922886Sopenharmony_ci#include "avqueue_item.h"
2380922886Sopenharmony_ci
2480922886Sopenharmony_cinamespace OHOS::AVSession {
2580922886Sopenharmony_ciclass DistributedObjectAdapter {
2680922886Sopenharmony_cipublic:
2780922886Sopenharmony_ci    using ObjectCallbackType = std::function<void(const std::vector<std::string>& keys)>;
2880922886Sopenharmony_ci    using ObjectDisconnectNotifier = std::function<void(const std::string& deviceId)>;
2980922886Sopenharmony_ci
3080922886Sopenharmony_ci    explicit DistributedObjectAdapter(const std::string& name);
3180922886Sopenharmony_ci
3280922886Sopenharmony_ci    ~DistributedObjectAdapter();
3380922886Sopenharmony_ci
3480922886Sopenharmony_ci    int32_t CreateObject();
3580922886Sopenharmony_ci
3680922886Sopenharmony_ci    int32_t PutData(const std::string& key, std::vector<uint8_t>& data);
3780922886Sopenharmony_ci
3880922886Sopenharmony_ci    int32_t GetData(const std::string& key, std::vector<uint8_t>& data);
3980922886Sopenharmony_ci
4080922886Sopenharmony_ci    void SetCallback(const ObjectCallbackType& callback);
4180922886Sopenharmony_ci
4280922886Sopenharmony_ci    void SetDisconnectNotifier(const ObjectDisconnectNotifier& notifer);
4380922886Sopenharmony_ci
4480922886Sopenharmony_ci    class AVSessionObjectWatcher : public ObjectStore::ObjectWatcher {
4580922886Sopenharmony_ci    public:
4680922886Sopenharmony_ci        explicit AVSessionObjectWatcher(const ObjectCallbackType& callback);
4780922886Sopenharmony_ci        void OnChanged(const std::string &name, const std::vector<std::string> &keys) override;
4880922886Sopenharmony_ci        virtual ~AVSessionObjectWatcher() = default;
4980922886Sopenharmony_ci    private:
5080922886Sopenharmony_ci        ObjectCallbackType callback_;
5180922886Sopenharmony_ci    };
5280922886Sopenharmony_ci
5380922886Sopenharmony_ci    class AVSessionStatusNotifier : public ObjectStore::StatusNotifier {
5480922886Sopenharmony_ci    public:
5580922886Sopenharmony_ci        explicit AVSessionStatusNotifier(const ObjectDisconnectNotifier& notifier);
5680922886Sopenharmony_ci        void OnChanged(const std::string &name, const std::string &networkId,
5780922886Sopenharmony_ci                       const std::string &onlineStatus) override;
5880922886Sopenharmony_ci        virtual ~AVSessionStatusNotifier() = default;
5980922886Sopenharmony_ci    private:
6080922886Sopenharmony_ci        ObjectDisconnectNotifier notifier_;
6180922886Sopenharmony_ci    };
6280922886Sopenharmony_ci
6380922886Sopenharmony_ciprivate:
6480922886Sopenharmony_ci    ObjectStore::DistributedObject *object_ {};
6580922886Sopenharmony_ci    std::string name_;
6680922886Sopenharmony_ci
6780922886Sopenharmony_ci    static inline const char AVSESSION_NAME[] = "ohos.avsession";
6880922886Sopenharmony_ci    static inline const char DOBJECT_KEY_META[] = "meta";
6980922886Sopenharmony_ci    static inline const char DOBJECT_KEY_STATE[] = "state";
7080922886Sopenharmony_ci    static inline const char DOBJECT_KEY_CMD[] = "cmd";
7180922886Sopenharmony_ci};
7280922886Sopenharmony_ci}
7380922886Sopenharmony_ci#endif // AVSESSION_DISTRIBUTEDOBJECT_ADAPTER_H