1 /*
2  * Copyright (c) 2020-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 #include "camera_client.h"
17 #include "media_log.h"
18 #include "samgr_lite.h"
19 #include "camera_type.h"
20 #include "ipc_skeleton.h"
21 
22 #include <cstdio>
23 
HOS_SystemInit(void)24 extern "C" void __attribute__((weak)) HOS_SystemInit(void)
25 {
26     SAMGR_Bootstrap();
27 }
28 
29 using namespace std;
30 namespace OHOS {
31 namespace Media {
GetInstance()32 CameraClient *CameraClient::GetInstance()
33 {
34     static CameraClient client;
35     return &client;
36 }
37 
InitCameraClient()38 bool CameraClient::InitCameraClient()
39 {
40     HOS_SystemInit();
41     if (proxy_ == nullptr) {
42         IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SERVICE_NAME);
43         if (iUnknown == nullptr) {
44             MEDIA_ERR_LOG("Camera server connecting failed.");
45             return false;
46         }
47         (void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&proxy_);
48         if (proxy_ == nullptr) {
49             MEDIA_ERR_LOG("QueryInterface failed.");
50             return false;
51         }
52     }
53     return true;
54 }
55 
GetIClientProxy()56 IClientProxy *CameraClient::GetIClientProxy()
57 {
58     return proxy_;
59 }
60 }
61 }
62