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 = false;
48     ReadBool(req, &enable);
49     int32_t ret = OnSetScreenSaverState((IUnknown *)iProxy, enable ? TRUE : FALSE);
50     WriteInt32(reply, ret);
51     return EC_SUCCESS;
52 }
53 
FeatureInvoke(IServerProxy * iProxy,int32_t funcId,void * origin,IpcIo * req,IpcIo * reply)54 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply)
55 {
56     if ((iProxy == NULL) || (req == NULL)) {
57         POWER_HILOGE("Invalid parameter");
58         return EC_INVALID;
59     }
60     POWER_HILOGD("Screen saver feature invoke function id: %d", funcId);
61     int32_t ret = EC_SUCCESS;
62     switch (funcId) {
63         case SCREENSAVER_FUNCID_SETSTATE:
64             ret = SetStateInvoke(iProxy, origin, req, reply);
65             break;
66         default:
67             POWER_HILOGE("Invalid function id: %d", funcId);
68             break;
69     }
70     return ret;
71 }
72