1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_REMOTE_SESSION_SYNCER_IMPL_H 17 #define OHOS_REMOTE_SESSION_SYNCER_IMPL_H 18 19 #include "avsession_info.h" 20 #include "avmeta_data.h" 21 #include "avplayback_state.h" 22 #include "avcontrol_command.h" 23 #include "remote_session_syncer.h" 24 #include "distributed_object.h" 25 #include "distributed_objectstore.h" 26 #include "objectstore_errors.h" 27 #include "avsession_errors.h" 28 #include "avsession_log.h" 29 30 namespace OHOS::AVSession { 31 using namespace ObjectStore; 32 class RemoteSessionSyncerImpl : public RemoteSessionSyncer, public ObjectWatcher, public StatusNotifier, 33 public std::enable_shared_from_this<RemoteSessionSyncerImpl> { 34 public: 35 RemoteSessionSyncerImpl(const std::string& sourceSessionId, const std::string& sourceDevice, 36 const std::string& sinkDevice); 37 38 int32_t Init() override; 39 40 int32_t PutAVMetaData(const AVMetaData& metaData) override; 41 42 int32_t GetAVMetaData(AVMetaData& metaData) override; 43 44 int32_t PutAVPlaybackState(const AVPlaybackState& state) override; 45 46 int32_t GetAVPlaybackState(AVPlaybackState& state) override; 47 48 int32_t PutControlCommand(const AVControlCommand& command) override; 49 50 int32_t GetControlCommand(AVControlCommand& command) override; 51 52 int32_t RegisterDataNotifier(const ObjectDataNotifier& notifier) override; 53 54 int32_t RegisterDisconnectNotifier(const ObjectDisconnectNotifier& notifier) override; 55 56 void OnChanged(const std::string &sessionId, const std::vector<std::string> &keys) override; 57 58 void OnChanged(const std::string &name, const std::string &networkId, const std::string &onlineStatus) override; 59 60 void Destroy() override; 61 62 ~RemoteSessionSyncerImpl() override; 63 64 static constexpr char METADATA_KEY[] = "metaData"; 65 static constexpr char PLAYBACK_STATE_KEY[] = "playbackState"; 66 static constexpr char CONTROL_COMMAND_KEY[] = "controlCommand"; 67 static constexpr int RECEIVE_DATA_SIZE_MAX = 500 * 1024; 68 const std::map<std::string, SessionDataCategory> categoryMap { 69 {METADATA_KEY, SESSION_DATA_META}, 70 {PLAYBACK_STATE_KEY, SESSION_DATA_PLAYBACK_STATE}, 71 {CONTROL_COMMAND_KEY, SESSION_DATA_CONTROL_COMMAND}, 72 }; 73 74 private: 75 int32_t PutData(const std::string &key, std::vector<uint8_t> &data); 76 77 int32_t GetData(const std::string &key, std::vector<uint8_t> &data); 78 79 std::string objectName_; 80 DistributedObject *object_; 81 DistributedObjectStore *objectStore_; 82 ObjectDataNotifier objectDataNotifier_; 83 ObjectDisconnectNotifier objectDisconnectNotifier_; 84 std::string sourceSessionId_; 85 std::string sourceDevice_; 86 std::string sinkDevice_; 87 }; 88 } // namespace OHOS::AVSession 89 #endif // OHOS_REMOTE_SESSION_SYNCER_IMPL_H