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 #include "dcamera.h"
17 #include <chrono>
18
19 namespace OHOS {
20 namespace DistributedHardware {
MapToExternalRetCode(DCamRetCode retCode)21 CamRetCode MapToExternalRetCode(DCamRetCode retCode)
22 {
23 switch (retCode) {
24 case DCamRetCode::SUCCESS:
25 return CamRetCode::NO_ERROR;
26 case DCamRetCode::CAMERA_BUSY:
27 return CamRetCode::CAMERA_BUSY;
28 case DCamRetCode::INVALID_ARGUMENT:
29 return CamRetCode::INVALID_ARGUMENT;
30 case DCamRetCode::METHOD_NOT_SUPPORTED:
31 return CamRetCode::METHOD_NOT_SUPPORTED;
32 case DCamRetCode::CAMERA_OFFLINE:
33 return CamRetCode::CAMERA_CLOSED;
34 case DCamRetCode::EXCEED_MAX_NUMBER:
35 return CamRetCode::INSUFFICIENT_RESOURCES;
36 case DCamRetCode::FAILED:
37 return CamRetCode::DEVICE_ERROR;
38 default:
39 break;
40 }
41 return CamRetCode::DEVICE_ERROR;
42 }
43
MapToInternalRetCode(CamRetCode retCode)44 DCamRetCode MapToInternalRetCode(CamRetCode retCode)
45 {
46 switch (retCode) {
47 case CamRetCode::NO_ERROR:
48 return DCamRetCode::SUCCESS;
49 case CamRetCode::CAMERA_BUSY:
50 return DCamRetCode::CAMERA_BUSY;
51 case CamRetCode::INSUFFICIENT_RESOURCES:
52 return DCamRetCode::EXCEED_MAX_NUMBER;
53 case CamRetCode::INVALID_ARGUMENT:
54 return DCamRetCode::INVALID_ARGUMENT;
55 case CamRetCode::METHOD_NOT_SUPPORTED:
56 return DCamRetCode::METHOD_NOT_SUPPORTED;
57 case CamRetCode::CAMERA_CLOSED:
58 return DCamRetCode::CAMERA_OFFLINE;
59 case CamRetCode::DEVICE_ERROR:
60 return DCamRetCode::FAILED;
61 default:
62 break;
63 }
64 return DCamRetCode::FAILED;
65 }
66
GetCurrentLocalTimeStamp()67 uint64_t GetCurrentLocalTimeStamp()
68 {
69 std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> tp =
70 std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
71 auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
72 return static_cast<uint64_t>(tmp.count());
73 }
74
SplitString(const std::string & str,std::vector<std::string> & tokens,const std::string & delimiters)75 void SplitString(const std::string &str, std::vector<std::string> &tokens, const std::string &delimiters)
76 {
77 std::string::size_type lastPos = 0;
78 std::string::size_type pos = str.find(delimiters);
79 while (std::string::npos != pos) {
80 tokens.push_back(str.substr(lastPos, pos - lastPos));
81 lastPos = pos + delimiters.size();
82 pos = str.find(delimiters, lastPos);
83 }
84 if (lastPos != str.length()) {
85 tokens.push_back(str.substr(lastPos));
86 }
87 }
88 } // end namespace DistributedHardware
89 } // end namespace OHOS