aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-11-16 09:52:34 +0000
committerAndy Williams <andy@andywilliams.me>2017-11-16 09:52:34 +0000
commite45396c48df3633b81caaa9833f85d92a83ed536 (patch)
treeba4e29f84b53e71792f230c46b87b3a8297c02e1 /reference
parenteina: Add struct value reference (diff)
downloadexamples-e45396c48df3633b81caaa9833f85d92a83ed536.tar.gz
eina: Add custom eina_value reference using timezone
Diffstat (limited to 'reference')
-rw-r--r--reference/c/eina/src/eina_value_custom.c171
-rw-r--r--reference/c/eina/src/meson.build7
2 files changed, 178 insertions, 0 deletions
diff --git a/reference/c/eina/src/eina_value_custom.c b/reference/c/eina/src/eina_value_custom.c
new file mode 100644
index 00000000..6b309e56
--- /dev/null
+++ b/reference/c/eina/src/eina_value_custom.c
@@ -0,0 +1,171 @@
+#define EFL_EO_API_SUPPORT 1
+#define EFL_BETA_API_SUPPORT 1
+
+#include <stdio.h>
+
+#include <Eina.h>
+#include <Efl_Core.h>
+
+static Eina_Bool
+_tz_setup(const Eina_Value_Type *type, void *mem)
+{
+ memset(mem, 0, type->value_size);
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_tz_flush(const Eina_Value_Type *type EINA_UNUSED, void *mem EINA_UNUSED)
+{
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_tz_copy(const Eina_Value_Type *type EINA_UNUSED, const void *src, void * dst)
+{
+ struct timezone *tzsrc = (struct timezone *)src;
+ struct timezone *tzdst = dst;
+ *tzdst = *tzsrc;
+ return EINA_TRUE;
+}
+
+static int
+_tz_compare(const Eina_Value_Type *type EINA_UNUSED, const void *a, const void *b)
+{
+ struct timezone tza = *(struct timezone*)a;
+ struct timezone tzb = *(struct timezone*)b;
+
+ if (tza.tz_minuteswest < tzb.tz_minuteswest)
+ return -1;
+ else if (tza.tz_minuteswest > tzb.tz_minuteswest)
+ return 1;
+ return 0;
+}
+
+static Eina_Bool
+_tz_pset(const Eina_Value_Type *type EINA_UNUSED, void *mem, const void *ptr)
+{
+ *(struct timezone*)mem = *(struct timezone*)ptr;
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_tz_vset(const Eina_Value_Type *type, void *mem, va_list args)
+{
+ const struct timezone tz = va_arg(args, struct timezone);
+ return _tz_pset(type, mem, &tz);
+}
+
+static Eina_Bool
+_tz_pget(const Eina_Value_Type *type, const void *mem, void *ptr)
+{
+ memcpy(ptr, mem, type->value_size);
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_tz_convert_to(const Eina_Value_Type *type EINA_UNUSED, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
+{
+ struct timezone v = *(struct timezone*)type_mem;
+
+ if (convert == EINA_VALUE_TYPE_UCHAR)
+ {
+ unsigned char val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_USHORT)
+ {
+ unsigned short val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_UINT)
+ {
+ unsigned int val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if ((convert == EINA_VALUE_TYPE_ULONG) || (convert == EINA_VALUE_TYPE_TIMESTAMP))
+ {
+ unsigned long val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_UINT64)
+ {
+ uint64_t val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_CHAR)
+ {
+ char val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_SHORT)
+ {
+ short val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_INT)
+ {
+ int val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_LONG)
+ {
+ long val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_INT64)
+ {
+ int64_t val_type = v.tz_minuteswest;
+ return eina_value_type_pset(convert, convert_mem, &val_type);
+ }
+ else if (convert == EINA_VALUE_TYPE_FLOAT)
+ return eina_value_type_pset(convert, convert_mem, &v.tz_minuteswest);
+ else if (convert == EINA_VALUE_TYPE_DOUBLE)
+ return eina_value_type_pset(convert, convert_mem, &v.tz_minuteswest);
+ else if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
+ convert == EINA_VALUE_TYPE_STRING)
+ {
+ const char *buf;
+ buf = eina_slstr_printf("+%03dh", v.tz_minuteswest);
+ return eina_value_type_pset(convert, convert_mem, &buf);
+ }
+ return EINA_FALSE;
+}
+
+static Eina_Value_Type TZ_TYPE = {
+ EINA_VALUE_TYPE_VERSION,
+ sizeof(struct timezone),
+ "struct timezone",
+ _tz_setup,
+ _tz_flush,
+ _tz_copy,
+ _tz_compare,
+ _tz_convert_to,
+ NULL, // No convert from
+ _tz_vset,
+ _tz_pset,
+ _tz_pget
+};
+
+EAPI_MAIN void
+efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+ Eina_Value value_tz;
+ struct timeval time;
+ struct timezone zone;
+ char *s;
+
+ eina_value_setup(&value_tz, &TZ_TYPE);
+
+ gettimeofday(&time, &zone);
+ eina_value_set(&value_tz, zone);
+
+ s = eina_value_to_string(&value_tz);
+ printf("Current timezone: %s\n", s);
+ free(s);
+
+ eina_value_free(&value_tz);
+
+ efl_exit(0);
+}
+EFL_MAIN()
+
diff --git a/reference/c/eina/src/meson.build b/reference/c/eina/src/meson.build
index 6872fbd0..29a640aa 100644
--- a/reference/c/eina/src/meson.build
+++ b/reference/c/eina/src/meson.build
@@ -34,3 +34,10 @@ executable('efl_reference_eina_value',
include_directories : inc,
install : true
)
+
+executable('efl_reference_eina_value_custom',
+ files(['eina_value_custom.c']),
+ dependencies : deps,
+ include_directories : inc,
+ install : true
+)