• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 SANE_SERVER_MANAGER_H
17 #define SANE_SERVER_MANAGER_H
18 
19 #include <mutex>
20 #include <map>
21 #include "system_ability.h"
22 #include "sane_backends_stub.h"
23 #include "scan_log.h"
24 #include "scan_constant.h"
25 #include "sane_control_param.h"
26 
27 namespace OHOS::Scan {
28 class SaneServerManager : public SystemAbility, public SaneBackendsStub {
29     DECLARE_SYSTEM_ABILITY(SaneServerManager);
30 
31 public:
32     SaneServerManager(int32_t saId, bool runOnCreate);
33     SaneServerManager();
34     ~SaneServerManager() override = default;
35 
36     void OnStart() override;
37 
38     ErrCode SaneInit(int32_t& status) override;
39     ErrCode SaneExit() override;
40     ErrCode SaneOpen(const std::string &scannerId, int32_t& status) override;
41     ErrCode SaneClose(const std::string &scannerId) override;
42     ErrCode SaneStart(const std::string &scannerId, int32_t& status) override;
43     ErrCode SaneCancel(const std::string &scannerId) override;
44     ErrCode SaneGetOptionDescriptor(const std::string &scannerId, int32_t saneOption,
45         SaneOptionDescriptor& saneOptDes, int32_t& status) override;
46     ErrCode SaneGetParameters(const std::string &scannerId, SaneParameters& spm, int32_t& status) override;
47     ErrCode SaneGetDevices(std::vector<SaneDevice>& deviceInfos, int32_t& status) override;
48     ErrCode SaneControlOption(const std::string& scannerId, const SaneControlParam& controlParam,
49         SaneOutParam& outParam, int32_t& status) override;
50     ErrCode SaneRead(const std::string& scannerId, const int32_t buflen,
51         SanePictureData& pictureData, int32_t& status) override;
52     ErrCode UnloadSystemAbility() override;
53 private:
54     bool CheckPermission();
55     SANE_Handle GetScanHandle(const std::string &scannerId);
56     SaneStatus GetControlOption(SANE_Handle& handle, const SaneControlParam& controlParam, SaneOutParam& outParam);
57     SaneStatus SetControlOption(SANE_Handle& handle, const SaneControlParam& controlParam, SaneOutParam& outParam);
58     void ConvertSaneDescriptor(const SANE_Option_Descriptor* saneDesc, SaneOptionDescriptor& saneOptDes);
59     std::map<std::string, SANE_Handle> scannerHandleList_;
60     std::mutex scannerHandleListlock_;
61 };
62 
63 } // namespace  OHOS::Scan
64 #endif