17418042dSoh_ci/*
27418042dSoh_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
37418042dSoh_ci * Licensed under the Apache License, Version 2.0 (the "License");
47418042dSoh_ci * you may not use this file except in compliance with the License.
57418042dSoh_ci * You may obtain a copy of the License at
67418042dSoh_ci *
77418042dSoh_ci *     http://www.apache.org/licenses/LICENSE-2.0
87418042dSoh_ci *
97418042dSoh_ci * Unless required by applicable law or agreed to in writing, software
107418042dSoh_ci * distributed under the License is distributed on an "AS IS" BASIS,
117418042dSoh_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127418042dSoh_ci * See the License for the specific language governing permissions and
137418042dSoh_ci * limitations under the License.
147418042dSoh_ci */
157418042dSoh_ci
167418042dSoh_ci#ifndef DISTRIBUTED_OBJECTSTORE_H
177418042dSoh_ci#define DISTRIBUTED_OBJECTSTORE_H
187418042dSoh_ci#include <memory>
197418042dSoh_ci#include <string>
207418042dSoh_ci#include <vector>
217418042dSoh_ci#include <functional>
227418042dSoh_ci
237418042dSoh_ci#include "distributed_object.h"
247418042dSoh_ci
257418042dSoh_cinamespace OHOS::ObjectStore {
267418042dSoh_ciclass StatusNotifier {
277418042dSoh_cipublic:
287418042dSoh_ci    virtual void OnChanged(
297418042dSoh_ci        const std::string &sessionId, const std::string &networkId, const std::string &onlineStatus) = 0;
307418042dSoh_ci};
317418042dSoh_ciclass DistributedObjectStore {
327418042dSoh_cipublic:
337418042dSoh_ci    virtual ~DistributedObjectStore(){};
347418042dSoh_ci
357418042dSoh_ci    /**
367418042dSoh_ci     * @brief Get the instance to handle the object, such as create the object.
377418042dSoh_ci     *
387418042dSoh_ci     * @param bundleName Indicates the bundleName.
397418042dSoh_ci     *
407418042dSoh_ci     * @return Returns the pointer to the DistributedObjectStore class.
417418042dSoh_ci     */
427418042dSoh_ci    static DistributedObjectStore *GetInstance(const std::string &bundleName = "");
437418042dSoh_ci
447418042dSoh_ci    /**
457418042dSoh_ci     * @brief Create a object according to the sessionId.
467418042dSoh_ci     *
477418042dSoh_ci     * @param sessionId Indicates the sessionId.
487418042dSoh_ci     *
497418042dSoh_ci     * @return Returns the pointer to the DistributedObject class.
507418042dSoh_ci     */
517418042dSoh_ci    virtual DistributedObject *CreateObject(const std::string &sessionId) = 0;
527418042dSoh_ci
537418042dSoh_ci    /**
547418042dSoh_ci     * @brief Create a object according to the sessionId.
557418042dSoh_ci     *
567418042dSoh_ci     * @param sessionId Indicates the sessionId.
577418042dSoh_ci     * @param status Indicates whether the distributed object is created successfully,
587418042dSoh_ci     * 0 means success, other means fail.
597418042dSoh_ci     *
607418042dSoh_ci     * @return Returns the pointer to the DistributedObject class.
617418042dSoh_ci     */
627418042dSoh_ci    virtual DistributedObject *CreateObject(const std::string &sessionId, uint32_t &status) = 0;
637418042dSoh_ci
647418042dSoh_ci    /**
657418042dSoh_ci     * @brief Get the double pointer to the object.
667418042dSoh_ci     *
677418042dSoh_ci     * @param sessionId Indicates the sessionId.
687418042dSoh_ci     * @param object Indicates the double pointer to the object.
697418042dSoh_ci     *
707418042dSoh_ci     * @return Returns 0 for success, others for failure.
717418042dSoh_ci     */
727418042dSoh_ci    virtual uint32_t Get(const std::string &sessionId, DistributedObject **object) = 0;
737418042dSoh_ci
747418042dSoh_ci    /**
757418042dSoh_ci     * @brief Delete the object according to the sessionId.
767418042dSoh_ci     *
777418042dSoh_ci     * @param sessionId Indicates the sessionId.
787418042dSoh_ci     *
797418042dSoh_ci     * @return Returns 0 for success, others for failure.
807418042dSoh_ci     */
817418042dSoh_ci    virtual uint32_t DeleteObject(const std::string &sessionId) = 0;
827418042dSoh_ci
837418042dSoh_ci    /**
847418042dSoh_ci     * @brief Set listening for data changes.
857418042dSoh_ci     *
867418042dSoh_ci     * @param object Indicates the pointer to the DistributedObject class.
877418042dSoh_ci     * @param objectWatcher Indicates callback function for data changes.
887418042dSoh_ci     *
897418042dSoh_ci     * @return Returns 0 for success, others for failure.
907418042dSoh_ci     */
917418042dSoh_ci    virtual uint32_t Watch(DistributedObject *object, std::shared_ptr<ObjectWatcher> objectWatcher) = 0;
927418042dSoh_ci
937418042dSoh_ci    /**
947418042dSoh_ci     * @brief Undo listening for data changes.
957418042dSoh_ci     *
967418042dSoh_ci     * @param object Indicates the pointer to the DistributedObject class.
977418042dSoh_ci     *
987418042dSoh_ci     * @return Returns the pointer to the DistributedObject class.
997418042dSoh_ci     */
1007418042dSoh_ci    virtual uint32_t UnWatch(DistributedObject *object) = 0;
1017418042dSoh_ci
1027418042dSoh_ci    /**
1037418042dSoh_ci     * @brief Set listening for device online and offline .
1047418042dSoh_ci     *
1057418042dSoh_ci     * @param notifier Indicates callback function for device online ond offline.
1067418042dSoh_ci     *
1077418042dSoh_ci     * @return Returns 0 for success, others for failure.
1087418042dSoh_ci     */
1097418042dSoh_ci    virtual uint32_t SetStatusNotifier(std::shared_ptr<StatusNotifier> notifier) = 0;
1107418042dSoh_ci
1117418042dSoh_ci    /**
1127418042dSoh_ci     * @brief Notify the status of the local device from the cached callback function according to the sessionId.
1137418042dSoh_ci     *
1147418042dSoh_ci     * @param sessionId Indicates the sessionId.
1157418042dSoh_ci     *
1167418042dSoh_ci     */
1177418042dSoh_ci    virtual void NotifyCachedStatus(const std::string &sessionId) = 0;
1187418042dSoh_ci};
1197418042dSoh_ci} // namespace OHOS::ObjectStore
1207418042dSoh_ci
1217418042dSoh_ci#endif // DISTRIBUTED_OBJECTSTORE_H
122