forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcefBase.c
110 lines (89 loc) · 2.93 KB
/
cefBase.c
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
// Copyright (c) 2014 The cefcapi authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/CzarekTomczak/cefcapi
// Website: https://github.com/fromkeith/cefcapi
#include "_cgo_export.h"
#include "cefBase.h"
#include <string.h>
// ----------------------------------------------------------------------------
// cef_base_t
// ----------------------------------------------------------------------------
///
// Structure defining the reference count implementation functions. All
// framework structures must include the cef_base_t structure first.
///
///
// Increment the reference count.
///
void CEF_CALLBACK add_ref(cef_base_t* self) {
go_AddRef((void *) self);
}
///
// Decrement the reference count. Delete this object when no references
// remain.
///
int CEF_CALLBACK release(cef_base_t* self) {
return go_Release((void *) self);
}
///
// Returns the current number of references.
///
int CEF_CALLBACK has_one_ref(cef_base_t* self) {
return go_HasOneReferenceCount((void *) self);
}
void add_refVoid(void* self) {
if (self == NULL) {
return;
}
((cef_base_t*) self)->add_ref((cef_base_t*) self);
}
int releaseVoid(void* self) {
if (self == NULL) {
return 1;
}
return ((cef_base_t*) self)->release((cef_base_t*) self);
}
void initialize_cef_base(cef_base_t* base, char *name) {
goDebugLog("initialize_cef_base\n");
// Check if "size" member was set.
size_t size = base->size;
// Let's print the size in case sizeof was used
// on a pointer instead of a structure. In such
// case the number will be very high.
//goDebugLog("cef_base_t.size = %lu\n", (unsigned long)size);
if (size <= 0) {
goDebugLog("FATAL: initialize_cef_base failed, size member not set\n");
_exit(1);
}
base->add_ref = add_ref;
base->release = release;
base->has_one_ref = has_one_ref;
go_CreateRef((void *) base, name);
}
//
// other base/shared items
//
// returns a utf8 encoded string that you need to delete
cef_string_utf8_t * cefStringToUtf8(const cef_string_t * source) {
cef_string_utf8_t * output = cef_string_userfree_utf8_alloc();
if (source == 0) {
return output;
}
cef_string_to_utf8(source->str, source->length, output);
return output;
}
cef_string_t * cefString16CastToCefString(cef_string_utf16_t * source) {
return (cef_string_t *) source;
}
cef_string_utf16_t * cefStringCastToCefString16(cef_string_t * source) {
return (cef_string_utf16_t *) source;
}
void appendToMultiMap(cef_string_multimap_t into, char *key, char *val) {
cef_string_t * keyCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(key, strlen(key), keyCef);
cef_string_t * valCef = cef_string_userfree_utf16_alloc();
cef_string_from_utf8(val, strlen(val), valCef);
cef_string_multimap_append(into, keyCef, valCef);
cef_string_userfree_utf16_free(keyCef);
cef_string_userfree_utf16_free(valCef);
}