summaryrefslogtreecommitdiff
path: root/libdevkit-power/dkp-enum.c
blob: 8cdcee944408a3294533c121b9b93ea086029b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
 * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include <glib.h>
#include <string.h>
#include "egg-debug.h"
#include "egg-string.h"

#include "dkp-enum.h"

/**
 * dkp_device_type_to_text:
 **/
const gchar *
dkp_device_type_to_text (DkpDeviceType type_enum)
{
	const gchar *type = NULL;
	switch (type_enum) {
	case DKP_DEVICE_TYPE_LINE_POWER:
		type = "line-power";
		break;
	case DKP_DEVICE_TYPE_BATTERY:
		type = "battery";
		break;
	case DKP_DEVICE_TYPE_UPS:
		type = "ups";
		break;
	case DKP_DEVICE_TYPE_MONITOR:
		type = "monitor";
		break;
	case DKP_DEVICE_TYPE_MOUSE:
		type = "mouse";
		break;
	case DKP_DEVICE_TYPE_KEYBOARD:
		type = "keyboard";
		break;
	case DKP_DEVICE_TYPE_PDA:
		type = "pda";
		break;
	case DKP_DEVICE_TYPE_PHONE:
		type = "phone";
		break;
	case DKP_DEVICE_TYPE_UNKNOWN:
		type = "unknown";
		break;
	default:
		g_assert_not_reached ();
		break;
	}
	return type;
}

/**
 * dkp_device_type_from_text:
 **/
DkpDeviceType
dkp_device_type_from_text (const gchar *type)
{
	if (type == NULL)
		return DKP_DEVICE_TYPE_UNKNOWN;
	if (egg_strequal (type, "line-power"))
		return DKP_DEVICE_TYPE_LINE_POWER;
	if (egg_strequal (type, "battery"))
		return DKP_DEVICE_TYPE_BATTERY;
	if (egg_strequal (type, "ups"))
		return DKP_DEVICE_TYPE_UPS;
	if (egg_strequal (type, "monitor"))
		return DKP_DEVICE_TYPE_MONITOR;
	if (egg_strequal (type, "mouse"))
		return DKP_DEVICE_TYPE_MOUSE;
	if (egg_strequal (type, "keyboard"))
		return DKP_DEVICE_TYPE_KEYBOARD;
	if (egg_strequal (type, "pda"))
		return DKP_DEVICE_TYPE_PDA;
	if (egg_strequal (type, "phone"))
		return DKP_DEVICE_TYPE_PHONE;
	return DKP_DEVICE_TYPE_UNKNOWN;
}

/**
 * dkp_device_state_to_text:
 **/
const gchar *
dkp_device_state_to_text (DkpDeviceState state_enum)
{
	const gchar *state = NULL;
	switch (state_enum) {
	case DKP_DEVICE_STATE_CHARGING:
		state = "charging";
		break;
	case DKP_DEVICE_STATE_DISCHARGING:
		state = "discharging";
		break;
	case DKP_DEVICE_STATE_EMPTY:
		state = "empty";
		break;
	case DKP_DEVICE_STATE_FULLY_CHARGED:
		state = "fully-charged";
		break;
	case DKP_DEVICE_STATE_UNKNOWN:
		state = "unknown";
		break;
	default:
		g_assert_not_reached ();
		break;
	}
	return state;
}

/**
 * dkp_device_state_from_text:
 **/
DkpDeviceState
dkp_device_state_from_text (const gchar *state)
{
	if (state == NULL)
		return DKP_DEVICE_STATE_UNKNOWN;
	if (egg_strequal (state, "charging"))
		return DKP_DEVICE_STATE_CHARGING;
	if (egg_strequal (state, "discharging"))
		return DKP_DEVICE_STATE_DISCHARGING;
	if (egg_strequal (state, "empty"))
		return DKP_DEVICE_STATE_EMPTY;
	if (egg_strequal (state, "fully-charged"))
		return DKP_DEVICE_STATE_FULLY_CHARGED;
	return DKP_DEVICE_STATE_UNKNOWN;
}

/**
 * dkp_device_technology_to_text:
 **/
const gchar *
dkp_device_technology_to_text (DkpDeviceTechnology technology_enum)
{
	const gchar *technology = NULL;
	switch (technology_enum) {
	case DKP_DEVICE_TECHNOLGY_LITHIUM_ION:
		technology = "lithium-ion";
		break;
	case DKP_DEVICE_TECHNOLGY_LITHIUM_POLYMER:
		technology = "lithium-polymer";
		break;
	case DKP_DEVICE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE:
		technology = "lithium-iron-phosphate";
		break;
	case DKP_DEVICE_TECHNOLGY_LEAD_ACID:
		technology = "lead-acid";
		break;
	case DKP_DEVICE_TECHNOLGY_NICKEL_CADMIUM:
		technology = "nickel-cadmium";
		break;
	case DKP_DEVICE_TECHNOLGY_NICKEL_METAL_HYDRIDE:
		technology = "nickel-metal-hydride";
		break;
	case DKP_DEVICE_TECHNOLGY_UNKNOWN:
		technology = "unknown";
		break;
	default:
		g_assert_not_reached ();
		break;
	}
	return technology;
}

/**
 * dkp_device_technology_from_text:
 **/
DkpDeviceTechnology
dkp_device_technology_from_text (const gchar *technology)
{
	if (technology == NULL)
		return DKP_DEVICE_TECHNOLGY_UNKNOWN;
	if (egg_strequal (technology, "lithium-ion"))
		return DKP_DEVICE_TECHNOLGY_LITHIUM_ION;
	if (egg_strequal (technology, "lithium-polymer"))
		return DKP_DEVICE_TECHNOLGY_LITHIUM_POLYMER;
	if (egg_strequal (technology, "lithium-iron-phosphate"))
		return DKP_DEVICE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE;
	if (egg_strequal (technology, "lead-acid"))
		return DKP_DEVICE_TECHNOLGY_LEAD_ACID;
	if (egg_strequal (technology, "nickel-cadmium"))
		return DKP_DEVICE_TECHNOLGY_NICKEL_CADMIUM;
	if (egg_strequal (technology, "nickel-metal-hydride"))
		return DKP_DEVICE_TECHNOLGY_NICKEL_METAL_HYDRIDE;
	return DKP_DEVICE_TECHNOLGY_UNKNOWN;
}

/**
 * dkp_qos_type_to_text:
 **/
const gchar *
dkp_qos_type_to_text (DkpQosType type)
{
	if (type == DKP_QOS_TYPE_NETWORK)
		return "network";
	if (type == DKP_QOS_TYPE_CPU_DMA)
		return "cpu_dma";
	return NULL;
}

/**
 * dkp_qos_type_from_text:
 **/
DkpQosType
dkp_qos_type_from_text (const gchar *type)
{
	if (egg_strequal (type, "network"))
		return DKP_QOS_TYPE_NETWORK;
	if (egg_strequal (type, "cpu_dma"))
		return DKP_QOS_TYPE_CPU_DMA;
	return DKP_QOS_TYPE_UNKNOWN;
}