Remove building with NOCRYPTO option
[minix.git] / minix / tests / ds / subs.c
blobd63ebe3b5f80c769d879f7fd46af603705f473d9
1 #include "inc.h"
3 char *key_u32 = "test_u32";
5 /* SEF functions and variables. */
6 static void sef_local_startup(void);
8 /*===========================================================================*
9 * main *
10 *===========================================================================*/
11 int main(void)
13 int r;
14 message mess;
15 char key[DS_MAX_KEYLEN];
16 int type;
17 u32_t num;
18 char string[17];
19 char buf[1000];
20 size_t length = 1000;
22 /* SEF local startup. */
23 sef_local_startup();
25 /* Subscribe. */
26 r = ds_subscribe(key_u32, DSF_INITIAL);
27 if(r != OK && r != EEXIST) {
28 printf("SUBSCRIBER: error in ds_subscribe: %d\n", r);
29 return -1;
32 while(1) {
33 /* Wait for a message. */
34 r = sef_receive(ANY, &mess);
35 if(r != OK) {
36 printf("SUBSCRIBER: sef_receive failed.\n");
37 return 1;
39 /* Only handle notifications from DS. */
40 if(mess.m_source != DS_PROC_NR)
41 continue;
43 /* Check which one was changed. */
44 r = ds_check(key, &type, NULL);
45 if(r == ENOENT) {
46 printf("SUBSCRIBER: the key %s was deleted.\n",
47 key);
48 continue;
50 if(r != OK) {
51 printf("SUBSCRIBER: error in ds_check.\n");
52 continue;
55 /* Retrieve the entry. */
56 printf("SUBSCRIBER: key: %s, ", key);
57 switch(type) {
58 case DSF_TYPE_U32:
59 r = ds_retrieve_u32(key, &num);
60 if(r != OK)
61 printf("error in ds_retrieve_u32.\n");
62 printf("U32: %d\n", num);
63 break;
64 case DSF_TYPE_STR:
65 r = ds_retrieve_str(key, string, sizeof(string)-1);
66 if(r != OK)
67 printf("error in ds_retrieve_str.\n");
68 printf("STR: %s\n", string);
69 break;
70 case DSF_TYPE_MEM:
71 r = ds_retrieve_mem(key, buf, &length);
72 if(r != OK)
73 printf("error in ds_retrieve_mem.\n");
74 break;
75 default:
76 printf("error in type! %d\n", type);
80 return 0;
83 /*===========================================================================*
84 * sef_local_startup *
85 *===========================================================================*/
86 static void sef_local_startup()
88 /* Let SEF perform startup. */
89 sef_startup();