Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1672 tullio 1
//package first_filter;
2
 
3
import java.io.*;
4
import java.net.*;
5
import java.util.List;
6
import java.util.ArrayList;
7
import java.util.Iterator;
8
import org.jdom.*;
9
import org.jdom.input.SAXBuilder;
10
import org.jdom.output.XMLOutputter;
11
import java.util.regex.*;
12
import java.util.Random;
13
 
14
/**
15
 * <p>Title: First XML filter</p>
16
 * <p>Description: </p>
17
 * <p>Copyright: Copyright (c) 2003</p>
18
 * <p>Company: Retis Lab</p>
19
 * @author not attributable
20
 * @version 1.0
21
 */
22
 
23
public class Application {
24
  private int numElements = 0;
25
  final String LOADFILE_DIR="../loadfile/";
26
  final String EVENT_DEFINE="event.c";
27
  final String ACT_LIST="event.c";
28
  private int servernumber=0;
29
  private timespec simulation_time=new timespec();
30
  ArrayList local_scheduler=new ArrayList();
31
  ArrayList Task_Section=new ArrayList();
32
  private int task_group=0;
33
  private int task_server=0;
34
  private int current_scheduler=0;
35
 
36
 
37
 
38
  //Construct the frame
39
  public Application() {
40
    try {
41
      jbInit();
42
    }
43
    catch(Exception e) {
44
      e.printStackTrace();
45
    }
46
  }
47
  //Component initialization
48
  private void jbInit() throws Exception  {
49
  }
50
 
51
  public void process (String url) throws MalformedURLException {
52
  try {
53
    //  Use SAXBuilder
54
    SAXBuilder builder =  new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
55
    builder.setFeature("http://apache.org/xml/features/validation/schema", true);
56
 
57
 
58
    Document doc = builder.build(url);
59
    Element root = doc.getRootElement();
60
 
61
    try {
62
      // Funzione per il salvataggio del file XML
63
      OutputStream fout = new FileOutputStream(EVENT_DEFINE);
64
      OutputStream bout = new BufferedOutputStream(fout);
65
      OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1");
66
      out.write("\n#include \"func.h\"\n");
67
 
68
      processElement (root,out);
69
      out.flush();
70
      out.close();
71
    } catch (UnsupportedEncodingException e) {
72
    System.out.println("Non sono supportati i caratteri latini");
73
    System.exit(1);
74
 
75
   } catch (IOException e){
76
    System.out.println("Salvatagio fallito");
77
    System.exit(1);
78
   }
79
 
80
 
81
 
82
    System.out.println ("Total Number of Elements Processed:  "
83
      +numElements);
84
  } catch (JDOMException e) {
85
    System.out.println ("JDOM Exception:  "+e.getMessage());
86
  } catch (java.io.IOException e) {
87
    System.out.println ("File Exception:  "+e.getMessage());
88
 
89
  }
90
}
91
 
92
//  Recursive Function to Process Elements
93
//  Prints the Element Name and keeps a running count
94
//  out total number of elements.
95
private void processElement(Element element, OutputStreamWriter out) {
96
  numElements++;
97
  String elementName = element.getName();
98
 
99
  System.out.println(elementName);
100
  List servers = element.getChildren();
101
  Iterator iterator = servers.iterator();
102
  /* get simulation parameter */
103
  Element SimulationInfo = (Element) iterator.next();
104
 
105
  Pattern pattern = Pattern.compile("[us\\s]+");
106
  try {
107
    /*simulation time */
108
 
109
    String[] stime = pattern.split(SimulationInfo.getChild("time").getText());
110
    out.write("struct timespec total_time={" + stime[0] + "," + stime[1] +
111
              "};\n\n");
112
    simulation_time.tv_sec = Long.valueOf(stime[0].trim()).longValue();
113
    simulation_time.tv_nsec = Long.valueOf(stime[1].trim()).longValue() /
114
        1000;
115
//float f = Float.valueOf(s.trim()).floatValue();
116
    /* server section start */
117
    out.write("struct loader_contract loader_contract_list[] = {\n");
118
    int total_server=0;
119
    while (iterator.hasNext()) {
120
      /* get server */
121
      Element server = (Element) iterator.next();
122
      process_server_section(server, out);
123
      total_server++;
124
    }
125
 
126
    out.write("};\n\n");
127
 
128
    out.write("int total_loader_contract="+total_server+";\n\n");
129
    iterator = local_scheduler.iterator();
130
    while (iterator.hasNext()) {
131
      /* get server */
132
      Element loc_sched = (Element) iterator.next();
133
      process_scheduler_section(loc_sched, out);
134
      task_server++;
135
    }
136
 
137
    iterator = Task_Section.iterator();
138
    int total_task_section=0;
139
    out.write("\nstruct loader_task loader_task_list[] = {\n");
140
    while (iterator.hasNext()) {
141
      /* get server */
142
      task_class tsk_sec = (task_class) iterator.next();
143
      out.write("   {\"" + tsk_sec.name + "\"," + tsk_sec.task_type + "," +
144
                tsk_sec.contract +
145
                "," + tsk_sec.localscheduler + "," + tsk_sec.number + ","
146
                + tsk_sec.group + ",{" + tsk_sec.deadline.tv_sec +
147
                "," +
148
                tsk_sec.deadline.tv_nsec + "}," + "{" +
149
                tsk_sec.wcet.tv_sec + "," +
150
                tsk_sec.wcet.tv_nsec + "}," + tsk_sec.act_number +
151
                ",0,act_" + tsk_sec.name +
152
                ",exec_" + tsk_sec.name + "},\n");
153
      total_task_section++;
154
    }
155
    out.write("};\n\n");
156
    out.write("int total_loader_task="+total_task_section+";\n\n");
157
 
158
 
159
  }
160
  catch (java.io.IOException e) {
161
    System.out.println("File Exception:  " + e.getMessage());
162
 
163
  }
164
 
165
}
166
 
167
void process_scheduler_section(Element e, OutputStreamWriter out) {
168
  Attribute t;
169
  t=e.getAttribute("type");
170
 
171
  List localpars = e.getChildren();
172
  Iterator iterator = localpars.iterator();
173
  while (iterator.hasNext()) {
174
    /* get task section */
175
    Element loc_task = (Element) iterator.next();
176
    process_task_section(loc_task, out, t);
177
 
178
  }
179
 
180
}
181
 
182
void process_task_section(Element e, OutputStreamWriter out, Attribute loc) {
183
  Attribute t;
184
  int act;
185
  act=1;
186
  int task_type=0;
187
  int localscheduler=0;
188
  timespec time = new timespec();
189
  Pattern pattern = Pattern.compile("[us\\s]+");
190
  String scheduler=loc.getValue();
191
  if (scheduler.equals("POSIX")) {
192
    localscheduler=30;
193
  }
194
  else if (scheduler.equals("EDF")) {
195
    localscheduler=31;
196
  }
197
  else if (scheduler.equals("RM")) {
198
    localscheduler=32;
199
  }
200
 
201
    /* get task section */
202
    t=e.getAttribute("type");
203
 
204
    if (t.getValue().equals("BackTask")) {
205
        process_back_task(e, out);
206
        task_type=23;
207
    } else if (t.getValue().equals("OneShot")) {
208
        process_oneshot_task(e, out);
209
        task_type=21;
210
    } else if (t.getValue().equals("CyclicalTask")) {
211
        task_type=22;
212
        act=process_cyclical_task(e, out);
213
    }
214
 
215
    task_class section=new task_class();
216
    section.deadline=new timespec();
217
    section.wcet=new timespec();
218
    section.name="task"+task_group;
219
    section.contract=task_server;
220
    section.group=task_group;
221
    section.act_number=act;
222
    section.task_type=task_type;
223
    section.localscheduler=localscheduler;
224
    section.number=Integer.valueOf(e.getChild("number").getText()).intValue();
225
 
226
    Element dl = e.getChild("dline");
227
    if (dl != null) {
228
 
229
      String[] dline=pattern.split(dl.getText());
230
      time.tv_sec = Long.valueOf(dline[0]).longValue();
231
      time.tv_nsec = Long.valueOf(dline[1]).longValue() * 1000;
232
 
233
      section.deadline.tv_sec=time.tv_sec;
234
      section.deadline.tv_nsec=time.tv_nsec;
235
 
236
    }
237
 
238
 
239
    Element wc = e.getChild("wcet");
240
    if (wc != null) {
241
 
242
      String[] wcet=pattern.split(e.getChild("wcet").getText());
243
      time.tv_sec = Long.valueOf(wcet[0]).longValue();
244
      time.tv_nsec = Long.valueOf(wcet[1]).longValue() * 1000;
245
 
246
      section.wcet.tv_sec=time.tv_sec;
247
      section.wcet.tv_nsec=time.tv_nsec;
248
 
249
    }
250
 
251
    Task_Section.add(section);
252
    task_group++;
253
 
254
}
255
 
256
void process_back_task(Element e, OutputStreamWriter out) {
257
 
258
    Pattern pattern = Pattern.compile("[us\\s]+");
259
 
260
    Element act_section=e.getChild("act_section");
261
    String[] start_time=pattern.split(act_section.getChild("start_time").getText());
262
    Element exec_section=e.getChild("exec_section");
263
 
264
    String[] exec_const=pattern.split(exec_section.getChild("exec_time").getText());
265
    try {
266
        out.write("struct timespec act_task"+task_group+"[]={{"+start_time[0]+","+start_time[1]+"},};\n\n");
267
        out.write("struct timespec exec_task"+task_group+"[]={{"+exec_const[0]+","+exec_const[1]+"},};\n\n");
268
 
269
    }
270
    catch (java.io.IOException ex) {
271
      System.out.println("File Exception:  " + ex.getMessage());
272
 
273
    }
274
}
275
void process_oneshot_task(Element e, OutputStreamWriter out) {
276
    Pattern pattern = Pattern.compile("[us\\s]+");
277
 
278
    Element act_section=e.getChild("act_section");
279
    String[] start_time=pattern.split(act_section.getChild("start_time").getText());
280
 
281
    Element exec_section=e.getChild("exec_section");
282
    String[] exec_const=pattern.split(exec_section.getChild("exec_time").getText());
283
 
284
    try {
285
      out.write("struct timespec act_task"+task_group+"[]={{"+start_time[0]+","+start_time[1]+"},};\n\n");
286
      out.write("struct timespec exec_task"+task_group+"[]={{"+exec_const[0]+","+exec_const[1]+"},};\n\n");
287
    }
288
    catch (java.io.IOException ex) {
289
      System.out.println("File Exception:  " + ex.getMessage());
290
    }
291
}
292
 
293
int process_cyclical_task(Element e, OutputStreamWriter out) {
294
 
295
    int activated=1;
296
    Pattern pattern = Pattern.compile("[us\\s]+");
297
    Element act_section=e.getChild("act_section");
298
    String[] start_time=pattern.split(act_section.getChild("start_time").getText());
299
    String[] period=pattern.split(act_section.getChild("period_time").getText());
300
    Element deltatime=act_section.getChild("delta_time");
301
    String[] delta_time;
302
 
303
    long act_delta=0;
304
    timespec delta_act_ts = new timespec();
305
 
306
    if (deltatime != null) {
307
        delta_time = pattern.split(deltatime.getText());
308
        delta_act_ts.tv_sec = Long.valueOf(delta_time[0]).longValue();
309
        delta_act_ts.tv_nsec = Long.valueOf(delta_time[1]).longValue() * 1000;
310
        act_delta = delta_act_ts.TIMESPEC2USEC();
311
    }
312
 
313
    Element exec_section=e.getChild("exec_section");
314
    String[] exec_const=pattern.split(exec_section.getChild("exec_time").getText());
315
    Element execdelta=exec_section.getChild("delta_time");
316
    String[] exec_delta;
317
 
318
    long exec_delta_long = 0;
319
    timespec exec_delta_ts = new timespec();
320
 
321
    if (execdelta != null) {
322
        exec_delta=pattern.split(execdelta.getText());
323
        exec_delta_ts.tv_sec = Long.valueOf(exec_delta[0]).longValue();
324
        exec_delta_ts.tv_nsec = Long.valueOf(exec_delta[1]).longValue() * 1000;
325
        exec_delta_long = exec_delta_ts.TIMESPEC2USEC();       
326
    }
327
 
328
    try {
329
      out.write("struct timespec act_task"+task_group+"[]={{"+
330
                start_time[0]+","+start_time[1]+"},\n");
331
 
332
    timespec time = new timespec();
333
    time.tv_sec = Long.valueOf(period[0]).longValue();
334
    time.tv_nsec = Long.valueOf(period[1]).longValue() * 1000;
335
 
336
    long usecperiod = time.TIMESPEC2USEC();
337
    timespec nextact = new timespec();
338
 
339
    time.tv_sec = Long.valueOf(start_time[0]).longValue();
340
    time.tv_nsec = Long.valueOf(start_time[1]).longValue() * 1000;
341
 
342
    Random rd = new Random();
343
 
344
    while (simulation_time.TIMESPEC_A_GT_B(time)) {
345
 
346
      nextact.tv_sec = Long.valueOf(period[0]).longValue();
347
      nextact.tv_nsec = Long.valueOf(period[1]).longValue() * 1000;
348
 
349
      if (act_delta != 0) {
350
        nextact.ADDUSEC2TIMESPEC((rd.nextInt() & Integer.MAX_VALUE) % act_delta - act_delta/2);
351
      }
352
 
353
      time.ADDUSEC2TIMESPEC(usecperiod);
354
      out.write("   {"+nextact.tv_sec+","+nextact.tv_nsec/1000+"},\n");
355
      activated++;
356
    }
357
    out.write("};\n");
358
 
359
    out.write("struct timespec exec_task"+task_group+"[]={\n");
360
 
361
    timespec nextexec = new timespec();
362
 
363
    for (int i=0; i<activated; i++) {
364
 
365
        nextexec.tv_sec = Long.valueOf(exec_const[0]).longValue();
366
        nextexec.tv_nsec = Long.valueOf(exec_const[1]).longValue() * 1000;
367
 
368
        if (exec_delta_long != 0) {
369
          nextexec.ADDUSEC2TIMESPEC((rd.nextInt() & Integer.MAX_VALUE) % exec_delta_long - exec_delta_long/2);
370
        }
371
 
372
        out.write("   {"+nextexec.tv_sec+","+nextexec.tv_nsec/1000+"},\n");
373
 
374
    }
375
    out.write("};\n");
376
  }
377
  catch (java.io.IOException ex) {
378
    System.out.println("File Exception:  " + ex.getMessage());
379
  }
380
 
381
  return activated;
382
}
383
 
384
void process_server_section(Element e, OutputStreamWriter out) {
385
 
386
 
387
  List serverpars = e.getChildren();
388
  Iterator iterator = serverpars.iterator();
389
  Element serverpar = (Element) iterator.next();
390
  String current_value;
391
  current_value=serverpar.getText();
392
  try {
393
    out.write("{" + servernumber + ",{");
394
    servernumber++;
395
 
396
    Pattern pattern = Pattern.compile("[us\\s]+");
397
    /* cmin */
398
    String[] cmin = pattern.split(current_value);
399
    out.write(cmin[0] + "," + Long.valueOf(cmin[1]).longValue()*1000+"},{");
400
 
401
    /* tmax */
402
    serverpar = (Element) iterator.next();
403
    current_value=serverpar.getText();
404
    String[] tmax = pattern.split(current_value);
405
    out.write(tmax[0] + "," + Long.valueOf(tmax[1]).longValue()*1000+"},{");
406
 
407
    /* cmax */
408
    serverpar = (Element) iterator.next();
409
    current_value=serverpar.getText();
410
    String[] cmax = pattern.split(current_value);
411
    out.write(cmax[0] + "," + Long.valueOf(cmax[1]).longValue()*1000+"},{");
412
 
413
    /* tmin */
414
    serverpar = (Element) iterator.next();
415
    current_value=serverpar.getText();
416
    String[] tmin = pattern.split(current_value);
417
    out.write(tmin[0] + "," + Long.valueOf(tmin[1]).longValue()*1000+"},");
418
 
419
    /*work load */
420
    serverpar = (Element) iterator.next();
421
    current_value=serverpar.getText();
422
    out.write(current_value+",");
423
 
424
    serverpar = (Element) iterator.next();
425
    current_value=serverpar.getName();
426
    Attribute loc_type=serverpar.getAttribute("type");
427
    String scheduler=loc_type.getValue();
428
    if (scheduler.equals("POSIX")) {
429
      out.write("30");
430
    }
431
    else if (scheduler.equals("EDF")) {
432
      out.write("31");
433
    }
434
    else if (scheduler.equals("RM")) {
435
      out.write("32");
436
    }
437
    out.write(",-1},\n");
438
    local_scheduler.add(servernumber-1,serverpar);
439
 
440
  } catch (java.io.IOException ex) {
441
    System.out.println ("File Exception:  "+ex.getMessage());
442
  }
443
 
444
  /*
445
    fprintf(file_event_header, "  {%d,{%d,%d},{%d,%d},{%d,%d},{%d,%d},%d,%d,-1},\n",
446
                           (int)c->number,(int)c->cmin.tv_sec,(int)c->cmin.tv_nsec,
447
                           (int)c->tmax.tv_sec,(int)c->tmax.tv_nsec,
448
                           (int)c->cmax.tv_sec,(int)c->cmax.tv_nsec,
449
                           (int)c->tmin.tv_sec,(int)c->tmin.tv_nsec,
450
                           (int)c->workload,(int)c->local_scheduler);
451
 
452
*/
453
    //processElement (kid);
454
  }
455
 
456
 
457
 
458
public static void main(String[] args) throws Exception {
459
  System.out.println("Parser Versione 1.0");
460
  Application app = new Application();
461
  if (args.length > 0)
462
    app.process(args[0]);
463
}
464
 
465
/* Event Generator
466
 *
467
 * Giacomo Guidi
468
 */
469
 
470
 
471
 
472
 
473
 
474
/*
475
int write_basic_par_start(void)
476
{
477
 
478
  FILE *file_event_header;
479
 
480
  file_event_header = fopen(EVENT_DEFINE,"a+");
481
  if (file_event_header == NULL) return 1;
482
 
483
  fprintf(file_event_header, "struct loader_task loader_task_list[] = {\n");
484
 
485
  fclose(file_event_header);
486
 
487
  return 0;
488
 
489
}
490
 
491
 
492
int write_basic_par(struct loader_task *c)
493
{
494
 
495
  FILE *file_event_header;
496
 
497
  file_event_header = fopen(EVENT_DEFINE,"a+");
498
  if (file_event_header == NULL) return 1;
499
 
500
  fprintf(file_event_header, "  {\"%s\",%d,%d,%d,%d,%d,{%d,%d},{%d,%d},%d,0,act_%s,exec_%s},\n",
501
                             c->name,(int)c->task_type,(int)c->server,(int)c->local_scheduler,(int)c->number,(int)c->group,
502
                             (int)c->deadline.tv_sec, (int)c->deadline.tv_nsec,
503
                             (int)c->wcet.tv_sec, (int)c->wcet.tv_nsec,
504
                             (int)c->act_number, c->name, c->name);
505
 
506
  fclose(file_event_header);
507
 
508
  return 0;
509
 
510
}
511
 
512
int write_contract(struct loader_contract *c)
513
{
514
 
515
  FILE *file_event_header;
516
 
517
  file_event_header = fopen(EVENT_DEFINE,"a+");
518
  if (file_event_header == NULL) return 1;
519
 
520
  fprintf(file_event_header, "  {%d,{%d,%d},{%d,%d},{%d,%d},{%d,%d},%d,%d,-1},\n",
521
                             (int)c->number,(int)c->cmin.tv_sec,(int)c->cmin.tv_nsec,
522
                             (int)c->tmax.tv_sec,(int)c->tmax.tv_nsec,
523
                             (int)c->cmax.tv_sec,(int)c->cmax.tv_nsec,
524
                             (int)c->tmin.tv_sec,(int)c->tmin.tv_nsec,
525
                             (int)c->workload,(int)c->local_scheduler);
526
 
527
  fclose(file_event_header);
528
 
529
  return 0;
530
 
531
}
532
 
533
int close_loader_task(int total_task_number)
534
{
535
 
536
  FILE *file_event_header;
537
 
538
  file_event_header = fopen(EVENT_DEFINE,"a+");
539
  if (file_event_header == NULL) return 1;
540
 
541
  fprintf(file_event_header,"};\n\n");
542
 
543
  fprintf(file_event_header,"int total_loader_task = %d;\n\n",total_task_number);
544
 
545
  fclose(file_event_header);
546
 
547
  return 0;
548
 
549
}
550
 
551
int close_loader_contract(int total_contract_number)
552
{
553
 
554
  FILE *file_event_header;
555
 
556
  file_event_header = fopen(EVENT_DEFINE,"a+");
557
  if (file_event_header == NULL) return 1;
558
 
559
  fprintf(file_event_header,"};\n\n");
560
 
561
  fprintf(file_event_header,"int total_loader_contract = %d;\n\n",total_contract_number);
562
 
563
  fclose(file_event_header);
564
 
565
  return 0;
566
 
567
}
568
 
569
int write_simulation_time(struct timespec *total)
570
{
571
 
572
  FILE *file_event_header;
573
 
574
  file_event_header = fopen(EVENT_DEFINE,"a+");
575
  if (file_event_header == NULL) return 1;
576
 
577
  fprintf(file_event_header,"struct timespec total_time = {%d,%d};\n\n",(int)total->tv_sec,(int)total->tv_nsec);
578
 
579
  fclose(file_event_header);
580
 
581
  return 0;
582
 
583
 
584
}
585
 
586
int write_single_act(struct timespec *t, struct loader_task *c)
587
{
588
 
589
  FILE *file_act_header;
590
 
591
  file_act_header = fopen(ACT_LIST,"a+");
592
  if (file_act_header == NULL) return 1;
593
 
594
  if (TIMESPEC_A_GT_B(t,&c->act_par_1)) {
595
    fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",c->name,
596
          (int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);
597
    c->act_number = 1;
598
  } else {
599
    fprintf(file_act_header,"struct timespec act_%s[] = {{0,0}};\n\n",c->name);
600
    c->act_number = 0;
601
  }
602
 
603
  fclose(file_act_header);
604
 
605
  return 0;
606
 
607
}
608
 
609
int write_periodic_act(struct timespec *t, struct loader_task *c)
610
{
611
 
612
  FILE *file_act_header;
613
  struct timespec tot_time;
614
  int period;
615
 
616
  file_act_header = fopen(ACT_LIST,"a+");
617
  if (file_act_header == NULL) return 1;
618
 
619
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
620
          (int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);
621
 
622
  c->act_number = 1;
623
  TIMESPEC_ASSIGN(&tot_time,&c->act_par_1);
624
  period = TIMESPEC2USEC(&c->act_par_2);
625
  while (TIMESPEC_A_GT_B(t, &tot_time)) {
626
    c->act_number++;
627
    ADDUSEC2TIMESPEC(period,&tot_time);
628
    fprintf(file_act_header,"  {%d,%d},\n",
629
            (int)c->act_par_2.tv_sec,(int)c->act_par_2.tv_nsec);
630
  }
631
 
632
  fprintf(file_act_header,"  };\n\n");
633
 
634
  fclose(file_act_header);
635
 
636
  return 0;
637
 
638
}
639
 
640
int write_mean_act(struct timespec *t,struct loader_task *c)
641
{
642
 
643
  FILE *file_act_header;
644
  struct timespec tot_time;
645
  int next_act;
646
 
647
  file_act_header = fopen(ACT_LIST,"a+");
648
  if (file_act_header == NULL) return 1;
649
 
650
  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
651
          (int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);
652
 
653
  c->act_number = 1;
654
  TIMESPEC_ASSIGN(&tot_time,&c->act_par_1);
655
  while (TIMESPEC_A_GT_B(t, &tot_time)) {
656
    c->act_number++;
657
    next_act = TIMESPEC2USEC(&c->act_par_2) + random() % TIMESPEC2USEC(&c->act_par_3) - TIMESPEC2USEC(&c->act_par_3) / 2;
658
    ADDUSEC2TIMESPEC(next_act,&tot_time);
659
    fprintf(file_act_header,"  {%d,%d},\n",
660
            next_act / 1000000, next_act % 1000000 * 1000);
661
  }
662
 
663
  fprintf(file_act_header,"  };\n\n");
664
 
665
  fclose(file_act_header);
666
 
667
  return 0;
668
 
669
}
670
 
671
int write_exec_const(struct loader_task *c)
672
{
673
 
674
  FILE *file_exec_header;
675
  int i;
676
 
677
  file_exec_header = fopen(ACT_LIST,"a+");
678
  if (file_exec_header == NULL) return 1;
679
 
680
  fprintf(file_exec_header,"struct timespec exec_%s[] =  {{%d,%d},\n",c->name,
681
          (int)c->exec_par_1.tv_sec,(int)c->exec_par_1.tv_nsec);
682
 
683
  for (i=0; i< c->act_number-1; i++)
684
    fprintf(file_exec_header,"  {%d,%d},\n",
685
          (int)c->exec_par_1.tv_sec,(int)c->exec_par_1.tv_nsec);
686
 
687
  fprintf(file_exec_header,"  };\n\n");
688
 
689
  fclose(file_exec_header);
690
 
691
  return 0;
692
 
693
}
694
 
695
int write_exec_mean(struct loader_task *c)
696
{
697
 
698
  FILE *file_exec_header;
699
  int exec_time_usec;
700
  int i;
701
 
702
  file_exec_header = fopen(ACT_LIST,"a+");
703
  if (file_exec_header == NULL) return 1;
704
 
705
  exec_time_usec = TIMESPEC2USEC(&c->exec_par_1)
706
                        + random() % TIMESPEC2USEC(&c->exec_par_2) - TIMESPEC2USEC(&c->exec_par_2) / 2;
707
  fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",c->name,
708
          exec_time_usec / 1000000, exec_time_usec % 1000000 * 1000);
709
 
710
  for (i=0; i< c->act_number-1; i++) {
711
    exec_time_usec = TIMESPEC2USEC(&c->exec_par_1)
712
                        + random() % TIMESPEC2USEC(&c->exec_par_2) - TIMESPEC2USEC(&c->exec_par_2) / 2;
713
    fprintf(file_exec_header,"  {%d,%d},\n",
714
          exec_time_usec / 1000000, exec_time_usec % 1000000 * 1000);
715
  }
716
 
717
  fprintf(file_exec_header,"  };\n\n");
718
 
719
  fclose(file_exec_header);
720
 
721
  return 0;
722
 
723
}
724
 
725
void *start;
726
void *end;
727
 
728
int main(int argc, char **argv) {
729
 
730
  char loadfile[100];
731
  struct timespec total_time;
732
  struct loader_task *start_loader_task = NULL, *current_t;
733
  struct loader_contract *start_loader_contract = NULL, *current_c;
734
  int err,ldnum;
735
  int total_task_number;
736
  int total_contract_number;
737
 
738
  printf("\nEvent Generator\n");
739
 
740
  if (argc < 2) {
741
    printf("Error: event_gen loadfile.fsf\n");
742
    exit(1);
743
  }
744
 
745
  printf("Read loader file %s\n",argv[1]);
746
 
747
  sprintf(loadfile,"%s%s",LOADFILE_DIR,argv[1]);
748
  err = dos_preload(loadfile,100000,&start,&end);
749
 
750
  if (err != 0) {
751
    printf("Error: File not found\n");
752
    exit(1);
753
  }
754
 
755
  printf("Parsing file\n");
756
 
757
  line_reader(start, end, &total_time, &start_loader_task, &start_loader_contract);
758
 
759
  srandom(time(NULL));
760
 
761
  write_struct();
762
 
763
  current_t = start_loader_task;
764
  ldnum = 1;
765
 
766
  while(current_t != NULL) {
767
 
768
    sprintf(current_t->name,"ltask%d",ldnum);
769
    current_t->group = ldnum;
770
    ldnum++;
771
 
772
    switch (current_t->act_type) {
773
     case PAR_ACT_SINGLE:
774
       err = write_single_act(&total_time,current_t);
775
        if (err != 0) {
776
          printf("Error writing activation header\n");
777
          exit(1);
778
        }
779
        break;
780
      case PAR_ACT_PERIODIC:
781
        err = write_periodic_act(&total_time,current_t);
782
        if (err != 0) {
783
          printf("Error writing activation header\n");
784
          exit(1);
785
        }
786
        break;
787
      case PAR_ACT_MEAN:
788
        err = write_mean_act(&total_time,current_t);
789
        if (err != 0) {
790
          printf("Error writing activation header\n");
791
          exit(1);
792
        }
793
        break;
794
    }
795
 
796
    switch (current_t->exec_type) {
797
      case PAR_EXEC_CONST:
798
        err = write_exec_const(current_t);
799
        if (err != 0) {
800
          printf("Error writing exec header\n");
801
          exit(1);
802
        }
803
        break;
804
      case PAR_EXEC_MEAN:
805
        err = write_exec_mean(current_t);
806
        if (err != 0) {
807
          printf("Error writing exec header\n");
808
          exit(1);
809
        }
810
        break;
811
    }
812
 
813
    current_t = current_t->next;
814
 
815
  }
816
 
817
  write_basic_par_start();
818
 
819
  total_task_number = 0;
820
  current_t = start_loader_task;
821
  while(current_t != NULL) {
822
 
823
    write_basic_par(current_t);
824
 
825
    current_t = current_t->next;
826
 
827
    total_task_number++;
828
 
829
  }
830
 
831
  close_loader_task(total_task_number);
832
 
833
  write_contract_start();
834
 
835
  total_contract_number = 0;
836
  current_c = start_loader_contract;
837
  while(current_c != NULL) {
838
 
839
    write_contract(current_c);
840
 
841
    current_c = current_c->next;
842
 
843
    total_contract_number++;
844
 
845
  }
846
 
847
  close_loader_contract(total_contract_number);
848
 
849
  write_simulation_time(&total_time);
850
 
851
  return 0;
852
 
853
}
854
 
855
*/
856
}