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 <ohos_errno.h>
17 #include <iproxy_server.h>
18
19 #include <pthread.h>
20 #include <unistd.h>
21
22 #include "hilog_wrapper.h"
23 #include "screen_saver_feature.h"
24
25 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply);
26
27 static ScreenSaverFeature g_feature = {
28 SCREEN_SAVER_FEATURE_INTERFACE_IMPL,
29 SERVER_IPROXY_IMPL_BEGIN,
30 .Invoke = FeatureInvoke,
31 SCREEN_SAVER_INTERFACE_IMPL,
32 IPROXY_END,
33 .identity = { -1, -1, NULL },
34 };
35
GetScreenSaverFeatureImpl(void)36 ScreenSaverFeature *GetScreenSaverFeatureImpl(void)
37 {
38 return &g_feature;
39 }
40
SetStateInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)41 static int32_t SetStateInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
42 {
43 if (reply == NULL) {
44 POWER_HILOGE("Invalid parameter");
45 return EC_INVALID;
46 }
47 bool enable = IpcIoPopBool(req);
48 int32_t ret = OnSetScreenSaverState((IUnknown *)iProxy, enable ? TRUE : FALSE);
49 IpcIoPushInt32(reply, ret);
50 return EC_SUCCESS;
51 }
52
FeatureInvoke(IServerProxy * iProxy,int32_t funcId,void * origin,IpcIo * req,IpcIo * reply)53 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply)
54 {
55 if ((iProxy == NULL) || (origin == NULL) || (req == NULL)) {
56 POWER_HILOGE("Invalid parameter");
57 return EC_INVALID;
58 }
59 POWER_HILOGD("Screen saver feature invoke function id: %d", funcId);
60 int32_t ret = EC_SUCCESS;
61 switch (funcId) {
62 case SCREENSAVER_FUNCID_SETSTATE:
63 ret = SetStateInvoke(iProxy, origin, req, reply);
64 break;
65 default:
66 POWER_HILOGE("Invalid function id: %d", funcId);
67 break;
68 }
69 return ret;
70 }
71