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 <cstdint>
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "api/visibility.h"
24 #include "serializable/serializable.h"
25 namespace OHOS::MiscServices {
26 class API_EXPORT ClipPlugin {
27 public:
28     enum EventStatus : uint32_t { EVT_UNKNOWN, EVT_INVALID, EVT_NORMAL, EVT_BUTT };
29     enum ServiceStatus : uint32_t { UNKNOWN = 0, IDLE, CONNECT_SUCC };
30 
31     struct GlobalEvent final : public DistributedData::Serializable {
32         uint8_t version = 0;
33         uint8_t frameNum = 0;
34         uint16_t user = 0;
35         uint16_t seqId = 0;
36         uint64_t expiration = 0;
37         uint16_t status = EVT_UNKNOWN;
38         std::string deviceId;
39         std::string account;
40         std::vector<std::string> dataType;
41         int32_t syncTime = 0;
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     class Factory {
50     public:
51         virtual ClipPlugin *Create() = 0;
52         virtual bool Destroy(ClipPlugin *) = 0;
53     };
54     static bool RegCreator(const std::string &name, Factory *factory);
55     static ClipPlugin *CreatePlugin(const std::string &name);
56     static bool DestroyPlugin(const std::string &name, ClipPlugin *plugin);
57 
58     virtual ~ClipPlugin();
59     virtual int32_t SetPasteData(const GlobalEvent &event, const std::vector<uint8_t> &data) = 0;
60     virtual std::pair<int32_t, int32_t> GetPasteData(const GlobalEvent &event, std::vector<uint8_t> &data) = 0;
61     virtual std::vector<GlobalEvent> GetTopEvents(uint32_t topN);
62     virtual std::vector<GlobalEvent> GetTopEvents(uint32_t topN, int32_t user);
63     virtual void Clear();
64     virtual int32_t PublishServiceState(const std::string &networkId, ServiceStatus status);
65     virtual void Clear(int32_t user);
66 
67 private:
68     static std::map<std::string, Factory *> factories_;
69 };
70 } // namespace OHOS::MiscServices
71 #endif // OHOS_DISTRIBUTED_DATA_PASTEBOARD_SERVICES_FRAMEWORK_CLIPS_PLUGIN_H
72