00001
00010
00011
00012
00013
00014
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <string.h>
00018
00019 #include <l4/events/events.h>
00020 #include <l4/log/l4log.h>
00021 #include <l4/rmgr/librmgr.h>
00022 #include <l4/sys/types.h>
00023 #include <l4/sys/syscalls.h>
00024 #include <l4/sys/ipc.h>
00025 #include <l4/sys/kdebug.h>
00026 #include <l4/util/getopt.h>
00027 #include <l4/util/util.h>
00028
00029 char LOG_tag[9]="ev_demo1";
00030
00032 static void eval_request(int value)
00033 {
00034 value = -value;
00035 if (value == L4EVENTS_OK)
00036 printf("Ok.\n");
00037
00038 if (value == L4EVENTS_WARNING_TASK_REGISTERED)
00039 printf("Task is already registered for eventtyp.\n");
00040
00041 if (value == L4EVENTS_WARNING_TASK_NOT_REGISTERED)
00042 printf("Task is not registered for eventtyp.\n");
00043
00044 if (value == L4EVENTS_WARNING_EVENTS_DELETED)
00045 printf("Some events are lost because of unregistering.\n");
00046
00047 if (value == L4EVENTS_WARNING_EVENTTYP_NOT_REGISTERED)
00048 printf("Eventtyp is not registered.\n");
00049
00050 if (value == L4EVENTS_WARNING_NO_EVENT_TO_RECEIVE)
00051 printf("There was no event to receive.\n");
00052
00053 if (value == L4EVENTS_WARNING_EVENT_PENDING)
00054 printf("This event is pending for some receiving tasks.\n");
00055
00056 if (value == L4EVENTS_ERROR_IPC)
00057 printf("There was an IPC error!\n");
00058
00059 if (value == L4EVENTS_ERROR_INTERNAL)
00060 printf("There was an internal event-server error!\n");
00061
00062 if (value == L4EVENTS_ERROR_TIMEOUT)
00063 printf("There was an IPC Timeout!\n");
00064
00065 if (value == L4EVENTS_ERROR_INVALID_COMMAND)
00066 printf("There was an invalid command!\n");
00067
00068 printf("\n");
00069 }
00070
00071
00072 int main(int argc, char* argv[])
00073 {
00074 int res;
00075 l4events_ch_t event_ch;
00076 l4events_nr_t event_nr;
00077 l4events_event_t send_evt, recv_evt;
00078
00079
00080
00081 printf("registering eventtyp 10.\n");
00082 eval_request(l4events_register(10, 0));
00083
00084 printf("registering eventtyp 11.\n");
00085 eval_request(l4events_register(11, 2));
00086
00087 printf("registering eventtyp 11 again.\n");
00088 eval_request(l4events_register(11, 3));
00089
00090 printf("registering eventtyp 12.\n");
00091 eval_request(l4events_register(12, 4));
00092
00093 printf("registering eventtyp 13.\n");
00094 eval_request(l4events_register(13, 5));
00095
00096 printf("registering eventtyp 14.\n");
00097 eval_request(l4events_register(14, 6));
00098
00099
00100
00101 printf("unregistering eventtyp 13.\n");
00102 eval_request(l4events_unregister(13));
00103
00104 printf("unregistering event 15.\n");
00105 eval_request(l4events_unregister(15));
00106
00107 l4events_dump();
00108
00109
00110
00111 strcpy(send_evt.str,"ABCDEFGHIJKLMNOPQRSTVW");
00112 send_evt.len = strlen(send_evt.str)+1;
00113
00114 printf("sending an event.\n");
00115 eval_request(l4events_send(10, &send_evt, &event_nr,
00116 L4EVENTS_ASYNC | L4EVENTS_SEND_ACK));
00117 printf("event_nr: %ld\n", event_nr);
00118
00119 l4events_dump();
00120
00121 event_ch = L4EVENTS_NO_CHANNEL;
00122
00123 printf("receiving an event.\n");
00124 res = l4events_receive(&event_ch, &recv_evt, &event_nr, L4_IPC_NEVER,
00125 L4EVENTS_RECV_ACK);
00126
00127
00128 if (res == L4EVENTS_OK)
00129 {
00130 printf("event_ch: %d", event_ch);
00131 printf("\n");
00132 printf("event: ");
00133 printf(recv_evt.str);
00134 printf("\n");
00135 printf("\n");
00136 }
00137 else
00138 {
00139 eval_request(res);
00140 }
00141
00142 l4events_dump();
00143 printf("give ack");
00144 res = l4events_give_ack(event_nr);
00145 l4events_dump();
00146
00147
00148
00149 strcpy(send_evt.str,"hello");
00150 send_evt.len = strlen(send_evt.str)+1;
00151
00152 printf("sending an event.\n");
00153 eval_request(l4events_send(12, &send_evt, &event_nr,
00154 L4EVENTS_ASYNC | L4EVENTS_SEND_ACK));
00155 printf("event_nr: %ld\n", event_nr);
00156
00157 strcpy(send_evt.str,"world");
00158 send_evt.len = strlen(send_evt.str)+1;
00159
00160 l4_sleep(50);
00161
00162 printf("sending an event.\n");
00163 eval_request(l4events_send(12, &send_evt, &event_nr, L4EVENTS_ASYNC));
00164 printf("event_nr: %ld\n", event_nr);
00165
00166 l4events_dump();
00167
00168 printf("unregister eventtyp 12 with loosing pending events.\n");
00169 eval_request(l4events_unregister(12));
00170
00171 l4events_dump();
00172
00173
00174
00175 strcpy(send_evt.str,"ab");
00176 send_evt.len = strlen(send_evt.str)+1;
00177
00178 printf("sending short event.\n");
00179 eval_request(l4events_send(14, &send_evt, &event_nr,
00180 L4EVENTS_ASYNC | L4EVENTS_SEND_ACK));
00181
00182 event_ch = 14;
00183
00184 printf("receiving a short event.\n");
00185 res = l4events_receive(&event_ch, &recv_evt, &event_nr,
00186 L4_IPC_NEVER, L4EVENTS_RECV_SHORT);
00187
00188 if (res == L4EVENTS_OK)
00189 {
00190 printf("event_ch: %d", event_ch);
00191 printf("\n");
00192 printf("event: ");
00193 printf(recv_evt.str);
00194 printf("\n");
00195 }
00196 else
00197 {
00198 eval_request(res);
00199 }
00200
00201
00202 printf("try to get notification for all sent events.\n");
00203 printf("event_nr:1\n");
00204 event_nr = 1;
00205 res = l4events_get_ack(&event_nr, L4_IPC_NEVER);
00206 printf("event_nr:2\n");
00207 event_nr = 2;
00208 res = l4events_get_ack(&event_nr, L4_IPC_NEVER);
00209 printf("event_nr:4\n");
00210 event_nr = 3;
00211 res = l4events_get_ack(&event_nr, L4_IPC_NEVER);
00212 printf("event_nr:5\n");
00213 event_nr = 4;
00214 res = l4events_get_ack(&event_nr, L4_IPC_NEVER);
00215 printf("res: %i\n", res);
00216
00217 printf("try to unregister all previous registered eventtyps.\n");
00218 eval_request(l4events_unregister_all());
00219
00220
00221 l4events_dump();
00222
00223 printf("stop.\n");
00224
00225 while (1) ;
00226
00227 return 0;
00228 };