1 /* 2 * Copyright (c) 2021 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 COMMON_EVENT_H 17 #define COMMON_EVENT_H 18 19 #include "common_event_manager.h" 20 #include "common_event_subscriber.h" 21 22 namespace OHOS::Request::Download { 23 constexpr const char *DOWNLOAD_EVENT = "com.ohos.downloaddataability"; 24 25 constexpr int DOWNLOAD_EVENT_CODE = 10000; 26 27 // action 28 constexpr int DOWNLOAD_INSERT = 0; 29 constexpr int DOWNLOAD_UPDATE = 1; 30 constexpr int DOWNLOAD_DELETE = 2; 31 32 class CommonEvent : public OHOS::EventFwk::CommonEventSubscriber { 33 public: CommonEvent(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)34 CommonEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo) : CommonEventSubscriber(subscriberInfo) 35 { 36 } 37 ~CommonEvent() = default; 38 static std::shared_ptr<CommonEvent> subscriber; 39 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data); 40 static bool PublishEvent(const OHOS::AAFwk::Want &want, int eventCode, const std::string &eventData); 41 static void UnregisterSubscriber(std::shared_ptr<OHOS::EventFwk::CommonEventSubscriber> subscriber); 42 static void RegisterSubscriber(); 43 static void SendChange(int actionCode); 44 }; 45 } // namespace OHOS::Request::Download 46 #endif // COMMON_EVENT_H