7 static int do_invoke_ds(message
*m
, int type
, const char *ds_name
)
13 if(type
== DS_CHECK
|| type
== DS_RETRIEVE_LABEL
) {
14 len_key
= DS_MAX_KEYLEN
;
17 len_key
= strlen(ds_name
)+1;
22 g_key
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
) ds_name
,
24 if(!GRANT_VALID(g_key
))
27 m
->DS_KEY_GRANT
= g_key
;
28 m
->DS_KEY_LEN
= len_key
;
30 r
= _taskcall(DS_PROC_NR
, type
, m
);
36 int ds_publish_label(const char *ds_name
, endpoint_t endpoint
, int flags
)
40 memset(&m
, 0, sizeof(m
));
41 m
.DS_VAL
= (u32_t
) endpoint
;
42 m
.DS_FLAGS
= DSF_TYPE_LABEL
| flags
;
43 return do_invoke_ds(&m
, DS_PUBLISH
, ds_name
);
46 int ds_publish_u32(const char *ds_name
, u32_t value
, int flags
)
50 memset(&m
, 0, sizeof(m
));
52 m
.DS_FLAGS
= DSF_TYPE_U32
| flags
;
53 return do_invoke_ds(&m
, DS_PUBLISH
, ds_name
);
56 static int ds_publish_raw(const char *ds_name
, void *vaddr
, size_t length
,
63 /* Grant for memory range. */
64 gid
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
)vaddr
, length
, CPF_READ
);
68 memset(&m
, 0, sizeof(m
));
70 m
.DS_VAL_LEN
= length
;
73 r
= do_invoke_ds(&m
, DS_PUBLISH
, ds_name
);
79 int ds_publish_str(const char *ds_name
, char *value
, int flags
)
82 length
= strlen(value
) + 1;
83 value
[length
- 1] = '\0';
84 return ds_publish_raw(ds_name
, value
, length
, flags
| DSF_TYPE_STR
);
87 int ds_publish_mem(const char *ds_name
, void *vaddr
, size_t length
, int flags
)
89 return ds_publish_raw(ds_name
, vaddr
, length
, flags
| DSF_TYPE_MEM
);
92 int ds_retrieve_label_name(char *ds_name
, endpoint_t endpoint
)
97 memset(&m
, 0, sizeof(m
));
98 m
.DS_VAL
= (u32_t
) endpoint
;
99 r
= do_invoke_ds(&m
, DS_RETRIEVE_LABEL
, ds_name
);
103 int ds_retrieve_label_endpt(const char *ds_name
, endpoint_t
*endpoint
)
108 memset(&m
, 0, sizeof(m
));
109 m
.DS_FLAGS
= DSF_TYPE_LABEL
;
110 r
= do_invoke_ds(&m
, DS_RETRIEVE
, ds_name
);
111 *endpoint
= (endpoint_t
) m
.DS_VAL
;
115 int ds_retrieve_u32(const char *ds_name
, u32_t
*value
)
120 memset(&m
, 0, sizeof(m
));
121 m
.DS_FLAGS
= DSF_TYPE_U32
;
122 r
= do_invoke_ds(&m
, DS_RETRIEVE
, ds_name
);
127 static int ds_retrieve_raw(const char *ds_name
, char *vaddr
, size_t *length
,
134 /* Grant for memory range. */
135 gid
= cpf_grant_direct(DS_PROC_NR
, (vir_bytes
)vaddr
, *length
, CPF_WRITE
);
136 if(!GRANT_VALID(gid
))
139 memset(&m
, 0, sizeof(m
));
141 m
.DS_VAL_LEN
= *length
;
143 r
= do_invoke_ds(&m
, DS_RETRIEVE
, ds_name
);
144 *length
= m
.DS_VAL_LEN
;
150 int ds_retrieve_str(const char *ds_name
, char *value
, size_t len_str
)
153 size_t length
= len_str
+ 1;
154 r
= ds_retrieve_raw(ds_name
, value
, &length
, DSF_TYPE_STR
);
155 value
[length
- 1] = '\0';
159 int ds_retrieve_mem(const char *ds_name
, char *vaddr
, size_t *length
)
161 return ds_retrieve_raw(ds_name
, vaddr
, length
, DSF_TYPE_MEM
);
164 int ds_delete_u32(const char *ds_name
)
168 memset(&m
, 0, sizeof(m
));
169 m
.DS_FLAGS
= DSF_TYPE_U32
;
170 return do_invoke_ds(&m
, DS_DELETE
, ds_name
);
173 int ds_delete_str(const char *ds_name
)
177 memset(&m
, 0, sizeof(m
));
178 m
.DS_FLAGS
= DSF_TYPE_STR
;
179 return do_invoke_ds(&m
, DS_DELETE
, ds_name
);
182 int ds_delete_mem(const char *ds_name
)
186 memset(&m
, 0, sizeof(m
));
187 m
.DS_FLAGS
= DSF_TYPE_MEM
;
188 return do_invoke_ds(&m
, DS_DELETE
, ds_name
);
191 int ds_delete_label(const char *ds_name
)
195 memset(&m
, 0, sizeof(m
));
196 m
.DS_FLAGS
= DSF_TYPE_LABEL
;
197 return do_invoke_ds(&m
, DS_DELETE
, ds_name
);
200 int ds_subscribe(const char *regexp
, int flags
)
204 memset(&m
, 0, sizeof(m
));
206 return do_invoke_ds(&m
, DS_SUBSCRIBE
, regexp
);
209 int ds_check(char *ds_key
, int *type
, endpoint_t
*owner_e
)
214 memset(&m
, 0, sizeof(m
));
215 r
= do_invoke_ds(&m
, DS_CHECK
, ds_key
);
216 if(type
) *type
= m
.DS_FLAGS
;
217 if(owner_e
) *owner_e
= m
.DS_OWNER
;