source: branches/fscctrl_safety_limits/dim/src/examples/test_server_priorities.c@ 19365

Last change on this file since 19365 was 11071, checked in by tbretz, 14 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 3.3 KB
Line 
1#include <stdio.h>
2#include <dis.h>
3
4char str[10][80];
5
6typedef struct {
7 int i;
8 int j;
9 int k;
10 double d;
11 short s;
12 char c;
13 short t;
14 float f;
15 char str[20];
16}TT;
17
18TT t;
19
20void cmnd_rout(tag, buf, size)
21int *tag, *size;
22TT *buf;
23{
24int i,*ptr;
25
26 printf("Command received, size = %d, TT size = %d:\n", *size,
27 sizeof(TT));
28 printf("buf->i = %d, buf->d = %2.2f, buf->s = %d, buf->c = %c, buf->f = %2.2f, buf->str = %s\n",
29 buf->i,buf->d,buf->s,buf->c,buf->f,buf->str);
30}
31
32void client_exited(tag)
33int *tag;
34{
35 char name[84];
36 char *ptr;
37
38 if(dis_get_client(name))
39 printf("Client %s (%d) exited\n", name, *tag);
40 else
41 printf("Client %d exited\n", *tag);
42}
43
44/*
45#ifdef WIN32
46#include <windows.h>
47#else
48#include <pthread.h>
49#endif
50
51#include <dic.h>
52
53void timr_rout(int tag)
54{
55 int code = 2004;
56#ifdef WIN32
57 DWORD id;
58 id = GetCurrentThreadId();
59#else
60 pthread_t id;
61 id = pthread_self();
62#endif
63 printf("in timr_rout, thread id = %d\n", id);
64 dic_cmnd_service("taskManager/sendKill", &code, sizeof(int));
65}
66
67void kill_rout(tag, buf, size)
68int *tag, *size;
69int *buf;
70{
71#ifdef WIN32
72 DWORD id;
73 id = GetCurrentThreadId();
74#else
75 pthread_t id;
76 id = pthread_self();
77#endif
78 printf("Command Kill received = %d\n", *buf);
79 printf("thread id = %d\n", id);
80 dim_set_priority(3, 1);
81}
82*/
83
84void exit_cmnd(code)
85int *code;
86{
87/*
88#ifdef WIN32
89 DWORD id;
90 id = GetCurrentThreadId();
91#else
92 pthread_t id;
93 id = pthread_self();
94#endif
95*/
96 printf("Exit_cmnd %d\n", *code);
97 exit(*code);
98/*
99 sleep(5);
100 printf("after_sleep, thread id = %d\n", id);
101 dim_set_priority(3, 60);
102 dtq_start_timer(5, timr_rout, 0);
103*/
104}
105
106main(argc,argv)
107int argc;
108char **argv;
109{
110 int i, j, id, *ptr;
111 char aux[80];
112 char name[84], *ptrc;
113
114 dis_add_exit_handler(exit_cmnd);
115 dis_add_client_exit_handler(client_exited);
116 for(i = 0; i< 10; i++)
117 {
118 sprintf(str[i],"%s/Service_%03d",argv[1],i);
119 dis_add_service( str[i], "C", str[i], strlen(str[i])+1,
120 (void *)0, 0 );
121 }
122 t.i = 123;
123 t.j = 123;
124 t.k = 123;
125 t.d = 56.78;
126 t.s = 12;
127 t.t = 12;
128 t.c = 'a';
129 t.f = 4.56;
130 ptr = (int *)&t;
131 strcpy(t.str,"hello world");
132
133 sprintf(aux,"%s/TEST_SWAP",argv[1]);
134 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
135 (void *)0, 0 );
136
137 sprintf(aux,"%s/TEST_CMD",argv[1]);
138 dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0);
139
140 dis_add_cmnd("taskManager/sendKill","I",kill_rout, 0);
141 dis_start_serving( argv[1] );
142/*
143 {
144 int prio = -1, ret, pclass = -1;
145 dim_get_scheduler_class(&pclass);
146 printf("Process class: %d\n",pclass);
147 dim_get_priority(1, &prio);
148 printf("Main Thread: %d\n",prio);
149 dim_get_priority(2, &prio);
150 printf("IO Thread: %d\n",prio);
151 dim_get_priority(3, &prio);
152 printf("Timer Thread: %d\n",prio);
153#ifndef WIN32
154 ret = dim_set_scheduler_class(2);
155 printf("ret = %d\n",ret);
156 ret = dim_set_priority(1, 20);
157 printf("ret = %d\n",ret);
158 ret = dim_set_priority(2, 50);
159 printf("ret = %d\n",ret);
160#endif
161 dim_get_scheduler_class(&pclass);
162 printf("Process class: %d\n",pclass);
163 dim_get_priority(1, &prio);
164 printf("Main Thread: %d\n",prio);
165 dim_get_priority(2, &prio);
166 printf("IO Thread: %d\n",prio);
167 dim_get_priority(3, &prio);
168 printf("Timer Thread: %d\n",prio);
169 }
170*/
171 if(dis_get_client(name))
172 {
173 printf("client %s\n",name);
174 }
175
176 while(1)
177 {
178 pause();
179 }
180/*
181 sleep(5);
182 {
183 int i;
184 for(i = 0; i <= 999999999; i++);
185 }
186 printf("Normal Exit\n");
187*/
188}
189
Note: See TracBrowser for help on using the repository browser.