1 /*
2 * Copyright (c) 2023-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 #ifndef OHOS_CAMERA_DPS_DPS_H
17 #define OHOS_CAMERA_DPS_DPS_H
18
19 #include "command_server.h"
20 #include "session_manager.h"
21 #include "scheduler_manager.h"
22
23 namespace OHOS {
24 namespace CameraStandard {
25 namespace DeferredProcessing {
26 int32_t DPS_Initialize();
27 void DPS_Destroy();
28
29 std::shared_ptr<CommandServer> DPS_GetCommandServer();
30 std::shared_ptr<SessionManager> DPS_GetSessionManager();
31 std::shared_ptr<SchedulerManager> DPS_GetSchedulerManager();
32
33 template <typename Command, typename Func, typename... Args>
SendCommandHelp(Func && func,Args &&...args)34 int32_t SendCommandHelp(Func&& func, Args&& ...args)
35 {
36 auto cmd = std::make_shared<Command>(std::forward<Args>(args)...);
37 if (cmd) {
38 auto server = DPS_GetCommandServer();
39 if (server) {
40 return (server.get()->*func)(cmd);
41 }
42 return DP_NULL_POINTER;
43 }
44 return DP_SEND_COMMAND_FAILED;
45 }
46
47 /**
48 * @brief Create the cmd and send.
49 *
50 * @param [IN] args: Parameter list for cmd.
51 *
52 * @return The DSP_OK status indicates successful execution of the command,
53 * while other statuses indicate failure.
54 */
55 template <typename Command, typename... Args>
DPS_SendCommand(Args &&...args)56 int32_t DPS_SendCommand(Args&& ...args)
57 {
58 return SendCommandHelp<Command>(&CommandServer::SendCommand, std::forward<Args>(args)...);
59 }
60
61 /**
62 * @brief Create the cmd and send it urgently.
63 *
64 * @param [IN] args: Parameter list for cmd.
65 *
66 * @return The DSP_OK status indicates successful execution of the command,
67 * while other statuses indicate failure.
68 */
69 template <typename Command, typename... Args>
DPS_SendUrgentCommand(Args &&...args)70 int32_t DPS_SendUrgentCommand(Args&& ...args)
71 {
72 return SendCommandHelp<Command>(&CommandServer::SendUrgentCommand, std::forward<Args>(args)...);
73 }
74 } // namespace DeferredProcessing
75 } // namespace CameraStandard
76 } // namespace OHOS
77 #endif // OHOS_CAMERA_DPS_DPS_H