Fixed: Coding rule issues.
[platform/core/connectivity/wifi-direct-manager.git] / src / wifi-direct-state.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /**
21  * This file implements wifi direct state functions.
22  *
23  * @file                wifi-direct-state.c
24  * @author      Gibyoung Kim (lastkgb.kim@samsung.com)
25  * @version     0.7
26  */
27
28 #include <stdio.h>
29 #include <glib.h>
30 #include <wifi-direct.h>
31
32 #include "wifi-direct-ipc.h"
33 #include "wifi-direct-manager.h"
34 #include "wifi-direct-state.h"
35 #include "wifi-direct-util.h"
36 #include "wifi-direct-log.h"
37
38
39 static char *_wfd_state_string(int state)
40 {
41         switch (state) {
42         case WIFI_DIRECT_STATE_DEACTIVATED:
43                 return "DEACTIVATED";
44         case WIFI_DIRECT_STATE_DEACTIVATING:
45                 return "DEACTIVATING";
46         case WIFI_DIRECT_STATE_ACTIVATING:
47                 return "ACTIVATING";
48         case WIFI_DIRECT_STATE_ACTIVATED:
49                 return "ACTIVATED";
50         case WIFI_DIRECT_STATE_DISCOVERING:
51                 return "DISCOVERING";
52         case WIFI_DIRECT_STATE_CONNECTING:
53                 return "CONNECTING";
54         case WIFI_DIRECT_STATE_DISCONNECTING:
55                 return "DISCONNECTING";
56         case WIFI_DIRECT_STATE_CONNECTED:
57                 return "CONNECTED";
58         case WIFI_DIRECT_STATE_GROUP_OWNER:
59                 return "GROUP_OWNER";
60         default:
61                 return "Unknown State";
62         }
63 }
64
65 int wfd_state_set(wfd_manager_s *manager, int state)
66 {
67         __WDS_LOG_FUNC_ENTER__;
68
69         if (!manager || state < WIFI_DIRECT_STATE_DEACTIVATED || state > WIFI_DIRECT_STATE_GROUP_OWNER) {
70                 WDS_LOGE("Invalid parameter");
71                 return -1;
72         }
73
74         WDS_LOGI("wifi-direct-manager state set [%s] -> [%s]",
75                                 _wfd_state_string(manager->state), _wfd_state_string(state));
76
77         manager->state = state;
78
79         __WDS_LOG_FUNC_EXIT__;
80         return 0;
81 }
82
83 int wfd_state_get(wfd_manager_s *manager, int *state)
84 {
85         __WDS_LOG_FUNC_ENTER__;
86
87         if (!manager || !state) {
88                 WDS_LOGE("Invalid parameter");
89                 return -1;
90         }
91
92         *state = manager->state;
93         WDS_LOGD("wifi-direct-manager state is %d", *state);
94
95         __WDS_LOG_FUNC_EXIT__;
96         return 0;
97 }