summaryrefslogtreecommitdiffstats
path: root/addons/deviceatlas/dummy/dac.c
blob: 720dc6af4d39ccabfc602fa57edf2680d61744d1 (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
#include "dac.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>

static char const __attribute__((unused)) rcsid[] = "$Id: dac.c, v dummy 1970/01/01 00:00:01 dcarlier Exp $";

struct da_bitset {
    unsigned long bits[8];
    size_t bit_count;
};

/*
 * Constructor/Destructor for possible globals.
 */

void
da_init()
{
}

void
da_fini()
{
}


void
da_seterrorfunc(da_errorfunc_t callback)
{
}

const char *
da_typename(da_type_t fieldtype)
{
   return "none";
}

char *
da_getdataversion(da_atlas_t *atlas)
{
    return "dummy library version 1.0";
}

time_t
da_getdatacreation(da_atlas_t *atlas)
{
    return time(NULL);
}

int
da_getdatarevision(da_atlas_t *atlas)
{
    return 1;
}

da_status_t
da_atlas_compile(void *ctx, da_read_fn readfn, da_setpos_fn rewind, void **ptr, size_t *size)
{
    return DA_OK;
}

da_status_t
da_atlas_open(da_atlas_t *atlas, da_property_decl_t *extraprops, const void *ptr, size_t len)
{
    void *ptr2 = malloc(len);
    free(ptr2);
    return ptr2 ? DA_OK : DA_NOMEM;
}

void
da_atlas_close(da_atlas_t *atlas)
{
}

da_evidence_id_t
da_atlas_clientprop_evidence_id(const da_atlas_t *atlas)
{
    return (da_evidence_id_t)2;
}

da_evidence_id_t
da_atlas_accept_language_evidence_id(const da_atlas_t *atlas)
{
    return (da_evidence_id_t)3;
}

da_evidence_id_t
da_atlas_header_evidence_id(const da_atlas_t *atlas, const char *evidence_name)
{
    return (da_evidence_id_t)1;
}

da_status_t
da_atlas_getproptype(const da_atlas_t *atlas, da_propid_t propid, da_type_t *type)
{
    *type = DA_TYPE_BOOLEAN;
    return DA_OK;
}

da_status_t
da_atlas_getpropname(const da_atlas_t *atlas, da_propid_t propid, const char **name)
{
    *name = "isRobot";
    return DA_OK;
}

da_status_t
da_atlas_getpropid(const da_atlas_t *atlas, const char *propname, da_propid_t *property)
{
    *property = (da_propid_t)1;
    return DA_OK;
}

size_t
da_atlas_getpropcount(const da_atlas_t *atlas)
{
    return 1;
}

void
da_atlas_setconfig(da_atlas_t *atlas, da_config_t *config)
{
}

da_status_t
da_searchv(const da_atlas_t *atlas, da_deviceinfo_t *result, da_evidence_t *evidence, size_t count)
{
    memset(result, 0, sizeof(*result));
    result->propcount = count;
    return DA_OK;
}

da_status_t
da_search(const da_atlas_t *atlas, da_deviceinfo_t *result, ...)
{
    da_evidence_t vec[4]; /* XXX: this will have to grow if more evidence is supported. */
    size_t i;
    va_list args;
    va_start(args, result);
    for (i = 0; i < sizeof vec / sizeof vec[0];) {
        vec[i].key = va_arg(args, da_evidence_id_t);
        if (vec[i].key == 0)
            break;
        vec[i++].value = va_arg(args, char *);
    }
    va_end(args);
    return da_searchv(atlas, result, vec, i);
}

/*
 * Search-result centric functions.
 */
size_t
da_getpropcount(const da_deviceinfo_t *info)
{
    return info->propcount;
}

da_status_t
da_getfirstprop(const da_deviceinfo_t *info, da_propid_t **propid)
{
    if (info->propcount == 0)
        return DA_NOMORE;
    *propid = &info->proplist[0];
    return DA_OK;
}

da_status_t
da_getnextprop(const da_deviceinfo_t *info, da_propid_t **propid)
{
    if (*propid - info->proplist >= info->propcount - 1)
        return DA_NOMORE;
    ++*propid;
    return DA_OK;
}

void
da_close(da_deviceinfo_t *sr)
{
}

da_status_t
da_getpropname(const da_deviceinfo_t *info, da_propid_t propid, const char **name)
{
    *name = "isRobot";
    return DA_OK;
}

da_status_t
da_getproptype(const da_deviceinfo_t *info, da_propid_t propid, da_type_t *type)
{
    *type = DA_TYPE_BOOLEAN;
    return DA_OK;
}

da_status_t
da_getpropinteger(const da_deviceinfo_t *info, da_propid_t property, long *vp)
{
     *vp = -1;
    return DA_OK;
}

da_status_t
da_getpropstring(const da_deviceinfo_t *info, da_propid_t property, const char **vp)
{
    *vp = NULL;
    return DA_OK;
}

da_status_t
da_getpropboolean(const da_deviceinfo_t *info, da_propid_t property, bool *vp)
{
    *vp = true;
    return DA_OK;
}

const char *
da_get_property_name(const da_atlas_t *atlas, da_propid_t property)
{
    return "isRobot";
}