• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "dk_container.h"
17 
18 #include <functional>
19 #include <iostream>
20 
21 namespace DriveKit {
22 
GetPrivateDatabase()23 std::shared_ptr<DKDatabase> DKContainer::GetPrivateDatabase()
24 {
25     return privateDatabase_;
26 }
27 
GetDatabaseWithdatabaseScope(DKDatabaseScope databaseScope)28 std::shared_ptr<DKDatabase> DKContainer::GetDatabaseWithdatabaseScope(DKDatabaseScope databaseScope)
29 {
30     std::shared_ptr<DKDatabase> database = nullptr;
31     switch (databaseScope) {
32         case DKDatabaseScope::DK_PUBLIC_DATABASE:
33             database = publicDatabase_;
34             break;
35         case DKDatabaseScope::DK_PRIVATE_DATABASE:
36             database = privateDatabase_;
37             break;
38         case DKDatabaseScope::DK_SHARED_DATABASE:
39             database = sharedDatabase_;
40             break;
41         default:
42             break;
43     }
44     return database;
45 }
46 
Init()47 void DKContainer::Init()
48 {
49     if (driveKit_) {
50         publicDatabase_ = std::make_shared<DKDatabase>(shared_from_this(), DKDatabaseScope::DK_PUBLIC_DATABASE);
51         if (publicDatabase_) {
52             publicDatabase_->Init();
53         }
54         privateDatabase_ = std::make_shared<DKDatabase>(shared_from_this(), DKDatabaseScope::DK_PRIVATE_DATABASE);
55         if (privateDatabase_) {
56             privateDatabase_->Init();
57         }
58         sharedDatabase_ = std::make_shared<DKDatabase>(shared_from_this(), DKDatabaseScope::DK_SHARED_DATABASE);
59         if (sharedDatabase_) {
60             sharedDatabase_->Init();
61         }
62     }
63 }
64 
SaveSubscription(std::shared_ptr<DKContext> contex,DKSubscription & subscription,SaveSubscriptionCallback callback)65 DKLocalErrorCode DKContainer::SaveSubscription(
66     std::shared_ptr<DKContext> contex,
67     DKSubscription &subscription,
68     SaveSubscriptionCallback callback)
69 {
70     return DKLocalErrorCode::NO_ERROR;
71 }
72 
DeleteSubscription(std::shared_ptr<DKContext> contex,DKSubscriptionId id,DelSubscriptionCallback callback)73 DKLocalErrorCode DKContainer::DeleteSubscription(
74     std::shared_ptr<DKContext> contex,
75     DKSubscriptionId id,
76     DelSubscriptionCallback callback)
77 {
78     return DKLocalErrorCode::NO_ERROR;
79 }
80 } // namespace DriveKit
81