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 };
42
CreateChain(const ChainType & type)43 shared_ptr<BaseHandler> NotifyResponsibilityChainFactory::CreateChain(const ChainType &type)
44 {
45 if (handlerMap_.count(type) > 0) {
46 list<shared_ptr<BaseHandler>>& handlerList = handlerMap_[type];
47 shared_ptr<BaseHandler> preHandler = nullptr;
48
49 for (const auto& handler : handlerList) {
50 if (preHandler != nullptr) {
51 preHandler->SetNextHandler(handler);
52 }
53 preHandler = handler;
54 }
55 return handlerList.front();
56 } else {
57 return nullptr;
58 }
59 }
60 } //namespace Media
61 } //namespace OHOS
62