summaryrefslogtreecommitdiff
path: root/TAO/examples/Simulator/Event_Supplier/Event_Sup.h
blob: 747a49f3a935703b1a354a0b0b2c85fb15381359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// $Id$
//
// ============================================================================
//
// 
// = FILENAME
//    Event_Sup.h
//
// = AUTHOR
//    originally
//    David Levine (levine@cs.wustl.edu) and
//    Tim Harrison (harrison@cs.wustl.edu)
//    modified
//    Michael Kircher (mk1@cs.wustl.edu)
//
// = DESCRIPTION
//   Event Supplier for the simulation
//
// ============================================================================

#if !defined (EVENT_SUP_H)
#define EVENT_SUP_H

#include <ctype.h>
#include <stdio.h>
#include "ace/OS.h"
#include "ace/SString.h"
#include "orbsvcs/RtecEventChannelAdminC.h"
#include "orbsvcs/RtecEventCommS.h"
#include "NavWeapC.h"

struct Schedule_Viewer_Data
{
  char operation_name [BUFSIZ];
  double utilitzation;
  double overhead;
  u_long arrival_time;
  u_long deadline_time;
  u_long completion_time;
  u_long computation_time;
};

class Demo_Supplier 
// = TITLE
//    Demo Supplier
//
// = DESCRIPTION
//    Generates event nofications and a shutdown message.
{
public:


  class Internal_Demo_Consumer : public POA_RtecEventComm::PushConsumer {
  public:
    virtual void push (const RtecEventComm::EventSet &events,
		       CORBA::Environment &);
    // The channel pushed some events to us.

    virtual void disconnect_push_consumer (CORBA::Environment &);
    // The channel is disconnecting.

  private:
    Internal_Demo_Consumer (Demo_Supplier* impl);
    friend class Demo_Supplier;

  private:
    Demo_Supplier* impl_;
  };

  
  // The following Supplier is needed because Demo_Supplier has not
  // inherited from PushSupplier, therefore we register with the 
  // following and send with Demo_Supplier

  class Internal_Demo_Supplier : public POA_RtecEventComm::PushSupplier {
  public:
    virtual void disconnect_push_supplier (CORBA::Environment &);

  private:
    Internal_Demo_Supplier (Demo_Supplier* impl);
    friend class Demo_Supplier;

  private:
    Demo_Supplier* impl_;
  };


  Demo_Supplier (unsigned int supplier_id);
  // Construction.  Requires the total number of messages to be
  // sent.  If the timestamp flag is enabled, then events are
  // timestamped, e.g., for use in measuring jitter.

  ~Demo_Supplier (void);
  
  int open_supplier (RtecEventChannelAdmin::EventChannel_ptr event_channel,
		     const char *name);
  // Registers with the name server under the given <name>.  Also
  // connects to the Event Channel as a supplier of notifications and
  // shutdown messages. 

  virtual void disconnect_push_supplier (CORBA::Environment &);
  // The channel is disconnecting.

  void start_generating_events (void);

  void load_schedule_data (
    ACE_Unbounded_Queue<Schedule_Viewer_Data *> &schedule_data);

  void insert_event_data (
    CORBA::Any &data, 
    ACE_Unbounded_Queue_Iterator<Schedule_Viewer_Data *> &schedule_iter);

  void push (const RtecEventComm::EventSet &events,
	     CORBA::Environment &);
  
protected:

  void shutdown (void);
  // Disconnect from the Event Service.

  // = Event Channel adminstration references.
  RtecEventChannelAdmin::EventChannel_var channel_admin_;
  RtecEventChannelAdmin::SupplierAdmin_var supplier_admin_;
  RtecEventChannelAdmin::ProxyPushConsumer_var proxy_consumer_;

  // Because we get timeout events in our internal_demo_consumer
  RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin_;
  RtecEventChannelAdmin::ProxyPushSupplier_var proxy_supplier_;

private:
  Navigation navigation_;
  Weapons weapons_;
  RtecScheduler::handle_t rt_info_;
  unsigned int supplier_id_;

  Internal_Demo_Consumer *internal_demo_consumer_;
  Internal_Demo_Supplier *internal_demo_supplier_;
};


#endif /* EVENT_SUP_H */