1 /* 2 * Copyright (c) 2022-2023 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_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_CLIPS_PLUGIN_H 17 #define OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_CLIPS_PLUGIN_H 18 #include <map> 19 20 #include "serializable/serializable.h" 21 22 namespace OHOS::MiscServices { 23 class API_EXPORT ClipPlugin { 24 public: 25 enum EventStatus : uint32_t { EVT_UNKNOWN, EVT_INVALID, EVT_NORMAL, EVT_BUTT }; 26 enum ServiceStatus : uint32_t { UNKNOWN = 0, IDLE, CONNECT_SUCC }; 27 28 struct GlobalEvent final : public DistributedData::Serializable { 29 uint8_t version = 0; 30 uint8_t frameNum = 0; 31 uint16_t user = 0; 32 uint16_t seqId = 0; 33 uint16_t status = EVT_UNKNOWN; 34 int32_t syncTime = 0; 35 uint32_t dataId = 0; 36 uint64_t expiration = 0; 37 bool isDelay = false; 38 std::string deviceId; 39 std::string account; 40 std::vector<std::string> dataType; 41 42 bool operator==(const GlobalEvent globalEvent) 43 { 44 return globalEvent.seqId == this->seqId && globalEvent.deviceId == this->deviceId; 45 } 46 bool Marshal(json &node) const override; 47 bool Unmarshal(const json &node) override; 48 }; 49 50 class Factory { 51 public: 52 virtual ClipPlugin *Create() = 0; 53 virtual bool Destroy(ClipPlugin *) = 0; 54 }; 55 56 using DelayDataCallback = std::function<int32_t(const GlobalEvent &, uint8_t, std::vector<uint8_t> &)>; 57 using DelayEntryCallback = std::function<int32_t(const GlobalEvent &, uint32_t, const std::string &, 58 std::vector<uint8_t> &)>; 59 using PreSyncCallback = std::function<void(const std::string &, ClipPlugin *)>; 60 using PreSyncMonitorCallback = std::function<void(void)>; 61 62 static bool RegCreator(const std::string &name, Factory *factory); 63 static ClipPlugin *CreatePlugin(const std::string &name); 64 static bool DestroyPlugin(const std::string &name, ClipPlugin *plugin); 65 66 virtual ~ClipPlugin(); 67 virtual int32_t SetPasteData(const GlobalEvent &event, const std::vector<uint8_t> &data) = 0; 68 virtual std::pair<int32_t, int32_t> GetPasteData(const GlobalEvent &event, std::vector<uint8_t> &data) = 0; 69 virtual std::vector<GlobalEvent> GetTopEvents(uint32_t topN); 70 virtual std::vector<GlobalEvent> GetTopEvents(uint32_t topN, int32_t user); 71 virtual void Clear(); 72 virtual int32_t PublishServiceState(const std::string &networkId, ServiceStatus status); 73 virtual void Clear(int32_t user); 74 virtual int32_t Close(int32_t user); 75 virtual void RegisterDelayCallback(const DelayDataCallback &dataCallback, const DelayEntryCallback &entryCallback); 76 virtual int32_t GetPasteDataEntry(const GlobalEvent &event, uint32_t recordId, const std::string &utdId, 77 std::vector<uint8_t> &rawData); 78 virtual void ChangeStoreStatus(int32_t userId); 79 virtual bool NeedSyncTopEvent(); 80 virtual void RegisterPreSyncCallback(const PreSyncCallback &callback); 81 virtual void RegisterPreSyncMonitorCallback(const PreSyncMonitorCallback &callback); 82 virtual void SendPreSyncEvent(int32_t userId); 83 84 private: 85 static std::map<std::string, Factory *> factories_; 86 }; 87 } // namespace OHOS::MiscServices 88 #endif // OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_CLIPS_PLUGIN_H 89