summaryrefslogtreecommitdiff
path: root/src/modules/ecordova/tizen/ecordova_device.c
blob: f60a9aa5ac355f55cf90072aaaa42dfa1e6a7086 (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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "ecordova_device_private.h"

#ifdef HAVE_TIZEN_INFO
#include <system/system_info.h>

#define MY_CLASS ECORDOVA_DEVICE_CLASS
#define MY_CLASS_NAME "Ecordova_Device"

static Eo_Base *
_ecordova_device_eo_base_constructor(Eo *obj, Ecordova_Device_Data *pd)
{
   DBG("(%p)", obj);

   pd->obj = obj;
   pd->uuid = NULL;
   pd->version = NULL;
   pd->model = NULL;
   pd->platform = NULL;

   return eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
}

static void
_ecordova_device_eo_base_destructor(Eo *obj, Ecordova_Device_Data *pd)
{
   DBG("(%p)", obj);

   free(pd->uuid);
   free(pd->version);
   free(pd->model);
   free(pd->platform);

   eo_do_super(obj, MY_CLASS, eo_destructor());
}

static const char *
_ecordova_device_ecordova_get(Eo *obj EINA_UNUSED,
                              Ecordova_Device_Data *pd EINA_UNUSED)
{
   ERR("Not implemented.");
   return NULL;
}

static const char *
_ecordova_device_model_get(Eo *obj EINA_UNUSED, Ecordova_Device_Data *pd)
{
   if (!pd->model)
     {
        int ret = system_info_get_platform_string("tizen.org/system/model_name",
                                                  &pd->model);
        EINA_SAFETY_ON_FALSE_RETURN_VAL(ret == SYSTEM_INFO_ERROR_NONE, NULL);
     }

   return pd->model;
}

static const char *
_ecordova_device_platform_get(Eo *obj EINA_UNUSED, Ecordova_Device_Data *pd)
{
   if (!pd->model)
     {
        int ret = system_info_get_platform_string("tizen.org/system/platform.name",
                                                  &pd->model);
        EINA_SAFETY_ON_FALSE_RETURN_VAL(ret == SYSTEM_INFO_ERROR_NONE, NULL);
     }

   return pd->model;
}

static const char *
_ecordova_device_uuid_get(Eo *obj EINA_UNUSED, Ecordova_Device_Data *pd)
{
   if (!pd->uuid)
     {
        int ret = system_info_get_platform_string("tizen.org/system/tizenid",
                                                  &pd->uuid);
        EINA_SAFETY_ON_FALSE_RETURN_VAL(ret == SYSTEM_INFO_ERROR_NONE, NULL);
     }

   return pd->uuid;
}

static const char *
_ecordova_device_version_get(Eo *obj EINA_UNUSED, Ecordova_Device_Data *pd)
{
   if (!pd->version)
     {
        // requires http://tizen.org/privilege/system  (and not "systeminfo")  privileges to be added in config.xml
        int ret = system_info_get_platform_string("tizen.org/feature/platform.version",
                                                  &pd->version);
        EINA_SAFETY_ON_FALSE_RETURN_VAL(ret == SYSTEM_INFO_ERROR_NONE, NULL);
     }

   return pd->version;
}

#include "ecordova_device.eo.c"
#endif