Skip to content

Latest commit

 

History

History
125 lines (105 loc) · 3.61 KB

usb_moded-ssu.c

File metadata and controls

125 lines (105 loc) · 3.61 KB
 
Aug 24, 2018
Aug 24, 2018
2
3
* @file usb_moded-ssu.c
*
Apr 9, 2019
Apr 9, 2019
4
* Copyright (C) 2016-2019 Jolla. All rights reserved.
Aug 24, 2018
Aug 24, 2018
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
*
* @author: Simo Piiroinen <simo.piiroinen@jollamobile.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Lesser GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* 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 Lesser 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
*/
22
23
#include "usb_moded-ssu.h"
Sep 5, 2018
Sep 5, 2018
24
25
26
#include "usb_moded-log.h"
Sep 5, 2018
Sep 5, 2018
27
28
29
30
31
#include <stdlib.h>
#include <string.h>
#include <ssusysinfo.h>
Aug 24, 2018
Aug 24, 2018
32
33
34
35
/* ========================================================================= *
* Prototypes
* ========================================================================= */
Apr 9, 2019
Apr 9, 2019
36
37
38
/* ------------------------------------------------------------------------- *
* SSU
* ------------------------------------------------------------------------- */
Aug 24, 2018
Aug 24, 2018
39
40
41
42
43
44
45
46
47
48
static void ssu_free_handle (void);
static ssusysinfo_t *ssu_get_handle (void);
gchar *ssu_get_manufacturer_name(void);
gchar *ssu_get_product_name (void);
/* ========================================================================= *
* Data
* ========================================================================= */
Dec 7, 2016
Dec 7, 2016
49
50
/** Cached ssu-sysinfo handle */
static ssusysinfo_t *ssu_instance = 0;
Dec 7, 2016
Dec 7, 2016
52
53
/** Flag for ssu-sysinfo instance has been initialized */
static gboolean ssu_intialized = FALSE;
Aug 24, 2018
Aug 24, 2018
55
56
57
58
/* ========================================================================= *
* Functions
* ========================================================================= */
Dec 7, 2016
Dec 7, 2016
59
60
/** Atexit callback for releasing cached ssu-sysinfo handle */
static void ssu_free_handle(void)
Feb 20, 2019
Feb 20, 2019
62
63
LOG_REGISTER_CONTEXT;
Dec 7, 2016
Dec 7, 2016
64
65
/* Make sure instance does not get created on exit path */
ssu_intialized = TRUE;
Dec 7, 2016
Dec 7, 2016
67
68
69
70
/* Release existing instance */
ssusysinfo_delete(ssu_instance),
ssu_instance = 0;
}
Dec 7, 2016
Dec 7, 2016
72
/** Helper for obtaining ssu-sysinfo handle on demand
Dec 7, 2016
Dec 7, 2016
74
* @return ssu-sysinfo, or NULL in case of errors
Dec 7, 2016
Dec 7, 2016
76
static ssusysinfo_t *ssu_get_handle(void)
Feb 20, 2019
Feb 20, 2019
78
79
LOG_REGISTER_CONTEXT;
Dec 7, 2016
Dec 7, 2016
80
81
82
83
84
85
86
/* Attempt only once */
if( !ssu_intialized ) {
ssu_intialized = TRUE;
ssu_instance = ssusysinfo_create();
atexit(ssu_free_handle);
}
return ssu_instance;
Dec 7, 2016
Dec 7, 2016
89
/** Read device manufacturer name from the SSU configuration
90
91
92
93
94
95
96
97
*
* Caller must release non-null return value with g_free().
*
* @return human readable string, or NULL in case of errors
*/
gchar *
ssu_get_manufacturer_name(void)
{
Feb 20, 2019
Feb 20, 2019
98
99
LOG_REGISTER_CONTEXT;
Dec 7, 2016
Dec 7, 2016
100
101
102
103
104
105
gchar *res = 0;
const char *val = ssusysinfo_device_manufacturer(ssu_get_handle());
if( val && strcmp(val, "UNKNOWN") )
res = g_strdup(val);
log_debug("%s() -> %s", __FUNCTION__, res ?: "N/A");
return res;
Dec 7, 2016
Dec 7, 2016
108
/** Read device model name from the SSU configuration
109
110
111
112
113
114
115
116
*
* Caller must release non-null return value with g_free().
*
* @return human readable string, or NULL in case of errors
*/
gchar *
ssu_get_product_name(void)
{
Feb 20, 2019
Feb 20, 2019
117
118
LOG_REGISTER_CONTEXT;
Dec 7, 2016
Dec 7, 2016
119
120
121
122
123
124
gchar *res = 0;
const char *val = ssusysinfo_device_pretty_name(ssu_get_handle());
if( val && strcmp(val, "UNKNOWN") )
res = g_strdup(val);
log_debug("%s() -> %s", __FUNCTION__, res ?: "N/A");
return res;