• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef PRINT_UTILS_H
17 #define PRINT_UTILS_H
18 
19 #include <string>
20 #include "want.h"
21 #include "bundle_mgr_client.h"
22 #include <nlohmann/json.hpp>
23 #include <mutex>
24 
25 #include <print_attributes.h>
26 
27 namespace OHOS::Print {
28 struct AdapterParam {
29     std::string documentName;
30     bool isCheckFdList;
31     PrintAttributes printAttributes;
32     std::string jobId;
33 };
34 
35 class PrintUtils {
36 public:
37     static std::string ToLower(const std::string &s);
38     static std::string GetExtensionId(const std::string &globalId);
39     static std::string GetGlobalId(const std::string& extensionId, const std::string& localId);
40     static std::string GetLocalId(const std::string& globalId, const std::string& extensionId);
41     static std::string EncodeExtensionCid(const std::string &extensionId, uint32_t callbackId);
42     static bool DecodeExtensionCid(const std::string &cid, std::string &extensionId, uint32_t &callbackId);
43     static std::string GetTaskEventId(const std::string &taskId, const std::string &type);
44     static int32_t OpenFile(const std::string &filePath);
45     static bool IsPathValid(const std::string &filePath);
46     static uint32_t GetIdFromFdPath(const std::string &fdPath);
47     static std::string GetJobStateChar(const uint32_t state);
48 
49     static void BuildAdapterParam(const std::shared_ptr<AdapterParam> &adapterParam, AAFwk::Want &want);
50     static void BuildPrintAttributesParam(const std::shared_ptr<AdapterParam> &adapterParam, AAFwk::Want &want);
51     static void ParseAttributesObjectParamForJson(const PrintAttributes &attrParam, nlohmann::json &attrJson);
52     static std::string GetBundleNameForUid(const int uid);
53     static std::string GetPrintJobId();
54     static std::string GetEventTypeWithToken(int64_t id, const std::string &type);
55     static std::string GetEventType(const std::string &type);
56 
57 private:
58     static std::mutex instanceLock_;
59 };
60 }  // namespace OHOS::Print
61 #endif  // PRINT_UTILS_H
62