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
->m_ds_req
.key_grant
= g_key
;
28 m
->m_ds_req
.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
.m_ds_req
.val_in
.ep
= endpoint
;
42 m
.m_ds_req
.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
));
51 m
.m_ds_req
.val_in
.u32
= value
;
52 m
.m_ds_req
.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
));
69 m
.m_ds_req
.val_in
.grant
= gid
;
70 m
.m_ds_req
.val_len
= length
;
71 m
.m_ds_req
.flags
= flags
;
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
.m_ds_req
.val_in
.ep
= 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
.m_ds_req
.flags
= DSF_TYPE_LABEL
;
110 r
= do_invoke_ds(&m
, DS_RETRIEVE
, ds_name
);
111 *endpoint
= m
.m_ds_reply
.val_out
.ep
;
115 int ds_retrieve_u32(const char *ds_name
, u32_t
*value
)
120 memset(&m
, 0, sizeof(m
));
121 m
.m_ds_req
.flags
= DSF_TYPE_U32
;
122 r
= do_invoke_ds(&m
, DS_RETRIEVE
, ds_name
);
123 *value
= m
.m_ds_reply
.val_out
.u32
;
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
));
140 m
.m_ds_req
.val_in
.grant
= gid
;
141 m
.m_ds_req
.val_len
= *length
;
142 m
.m_ds_req
.flags
= flags
;
143 r
= do_invoke_ds(&m
, DS_RETRIEVE
, ds_name
);
144 *length
= m
.m_ds_reply
.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
.m_ds_req
.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
.m_ds_req
.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
.m_ds_req
.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
.m_ds_req
.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
));
205 m
.m_ds_req
.flags
= flags
;
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
.m_ds_req
.flags
;
217 if(owner_e
) *owner_e
= m
.m_ds_req
.owner
;