1 /*
2 * Copyright (C) 2024 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 #include "notify_responsibility_chain_factory.h"
17
18 #include "notify_handler.h"
19 #include "analysis_handler.h"
20 #include "cloud_album_handler.h"
21 #include "uri_convert_handler.h"
22
23 using namespace std;
24
25 namespace OHOS {
26 namespace Media {
27
28 unordered_map<ChainType, list<shared_ptr<BaseHandler>>> NotifyResponsibilityChainFactory::handlerMap_ = {
29 {TRANSPARENT, {
30 make_shared<UriConvertHandler>(),
31 make_shared<NotifyHandler>()
32 }},
33 {PHOTODELETE, {
34 make_shared<AnalysisHandler>(),
35 make_shared<UriConvertHandler>(),
36 make_shared<NotifyHandler>()
37 }},
38 {ALBUM_DELETE, {
39 make_shared<CloudAlbumHandler>()
40 }},
41 {GALLERY_PHOTO_DELETE, {
42 make_shared<AnalysisHandler>(),
43 }},
44 };
45
CreateChain(const ChainType & type)46 shared_ptr<BaseHandler> NotifyResponsibilityChainFactory::CreateChain(const ChainType &type)
47 {
48 if (handlerMap_.count(type) > 0) {
49 list<shared_ptr<BaseHandler>>& handlerList = handlerMap_[type];
50 shared_ptr<BaseHandler> preHandler = nullptr;
51
52 for (const auto& handler : handlerList) {
53 handler->init();
54 if (preHandler != nullptr) {
55 preHandler->SetNextHandler(handler);
56 }
57 preHandler = handler;
58 }
59 return handlerList.front();
60 } else {
61 return nullptr;
62 }
63 }
64 } //namespace Media
65 } //namespace OHOS
66