~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/tests/Notify/Structured_Filter/Structured_Supplier.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Structured_Supplier.cpp,v 1.5 2003/07/06 21:41:57 pradeep Exp
2
 
 
3
 
// ******************************************************************
4
 
// Include Section
5
 
// ******************************************************************
6
 
 
7
 
#include "orbsvcs/CosNotifyChannelAdminS.h"
8
 
#include "orbsvcs/CosNotifyCommC.h"
9
 
#include "orbsvcs/CosNamingC.h"
10
 
#include "Notify_StructuredPushSupplier.h"
11
 
#include "controlS.h"
12
 
#include "Notify_Test_Client.h"
13
 
#include "tao/debug.h"
14
 
 
15
 
// ******************************************************************
16
 
// Data Section
17
 
// ******************************************************************
18
 
 
19
 
static CORBA::Boolean go = 0;
20
 
static CORBA::Short n_events = 1;
21
 
static const char* ior_file = "supplier.ior";
22
 
static TAO_Notify_Tests_StructuredPushSupplier* supplier = 0;
23
 
 
24
 
// ******************************************************************
25
 
// Subroutine Section
26
 
// ******************************************************************
27
 
 
28
 
class supplier_ctrl_i : public POA_supplier_ctrl
29
 
{
30
 
public:
31
 
  void ctrl (CORBA::Boolean flag,
32
 
             CORBA::Short num_events
33
 
             ACE_ENV_ARG_DECL)
34
 
    ACE_THROW_SPEC ((CORBA::SystemException));
35
 
};
36
 
 
37
 
 
38
 
void
39
 
supplier_ctrl_i::ctrl (CORBA::Boolean flag,
40
 
                       CORBA::Short num_events
41
 
                       ACE_ENV_ARG_DECL_NOT_USED /*ACE_ENV_SINGLE_ARG_PARAMETER*/)
42
 
  ACE_THROW_SPEC ((CORBA::SystemException))
43
 
{
44
 
  go = flag;
45
 
  n_events = num_events;
46
 
}
47
 
 
48
 
 
49
 
static CosNotifyChannelAdmin::SupplierAdmin_ptr
50
 
create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
51
 
                      ACE_ENV_ARG_DECL)
52
 
{
53
 
  CosNotifyChannelAdmin::AdminID adminid = 0;
54
 
  CosNotifyChannelAdmin::SupplierAdmin_var admin =
55
 
    ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
56
 
                           adminid
57
 
                           ACE_ENV_ARG_PARAMETER);
58
 
  ACE_CHECK_RETURN (0);
59
 
 
60
 
  return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
61
 
}
62
 
 
63
 
int
64
 
setup_event ()
65
 
{
66
 
  static int count = 0;
67
 
 
68
 
  CosNotification::StructuredEvent event;
69
 
 
70
 
   event.header.fixed_header.event_type.domain_name =
71
 
     CORBA::string_dup ("TAO Test Suite");
72
 
   event.header.fixed_header.event_type.type_name =
73
 
     CORBA::string_dup ("Filtered Structured Event Notification Svc test");
74
 
 
75
 
   if (count % 3 == 0)
76
 
    {
77
 
      event.header.fixed_header.event_name = CORBA::string_dup ("String test event");
78
 
      event.header.variable_header.length (1);
79
 
 
80
 
      event.filterable_data.length (2);
81
 
      event.filterable_data[0].name = CORBA::string_dup ("String");
82
 
      event.filterable_data[0].value <<= "One Hundred";
83
 
      event.filterable_data[1].name = CORBA::string_dup ("seq");
84
 
      event.filterable_data[1].value <<= (CORBA::Short) count;
85
 
    }
86
 
   else if (count % 3 == 1)
87
 
    {
88
 
      event.header.fixed_header.event_name = CORBA::string_dup ("Short test event");
89
 
      event.header.variable_header.length (1);
90
 
 
91
 
      event.filterable_data.length (2);
92
 
      event.filterable_data[0].name = CORBA::string_dup ("Number");
93
 
      event.filterable_data[0].value <<= (CORBA::Short) 100;
94
 
      event.filterable_data[1].name = CORBA::string_dup ("seq");
95
 
      event.filterable_data[1].value <<= (CORBA::Short) count;
96
 
    }
97
 
   else
98
 
    {
99
 
      event.header.fixed_header.event_name = CORBA::string_dup ("Short test event");
100
 
      event.header.variable_header.length (1);
101
 
 
102
 
      event.filterable_data.length (2);
103
 
      event.filterable_data[0].name = CORBA::string_dup ("Number");
104
 
      event.filterable_data[0].value <<= (CORBA::Short) 50;
105
 
      event.filterable_data[1].name = CORBA::string_dup ("seq");
106
 
      event.filterable_data[1].value <<= (CORBA::Short) count;
107
 
    }
108
 
 
109
 
  count++;
110
 
 
111
 
  ACE_TRY_NEW_ENV
112
 
    {
113
 
      if (TAO_debug_level)
114
 
        ACE_DEBUG ((LM_DEBUG, "%d sent \n", count));
115
 
 
116
 
      supplier->send_event (event ACE_ENV_ARG_PARAMETER);
117
 
      ACE_TRY_CHECK;
118
 
    }
119
 
  ACE_CATCH (CORBA::Exception, e)
120
 
    {
121
 
      ACE_PRINT_EXCEPTION (e, "Supplier Signal Exception: ");
122
 
    }
123
 
  ACE_ENDTRY;
124
 
 
125
 
  return 0;
126
 
}
127
 
 
128
 
static void create_supplier (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
129
 
                             PortableServer::POA_ptr poa
130
 
                             ACE_ENV_ARG_DECL)
131
 
{
132
 
  ACE_NEW_THROW_EX (supplier,
133
 
                    TAO_Notify_Tests_StructuredPushSupplier (),
134
 
                    CORBA::NO_MEMORY ());
135
 
 
136
 
  supplier->init (poa ACE_ENV_ARG_PARAMETER);
137
 
  ACE_CHECK;
138
 
 
139
 
  supplier->connect (admin ACE_ENV_ARG_PARAMETER);
140
 
  ACE_CHECK;
141
 
}
142
 
 
143
 
// ******************************************************************
144
 
// Main Section
145
 
// ******************************************************************
146
 
 
147
 
int main (int argc, char * argv[])
148
 
{
149
 
  int status = 0;
150
 
 
151
 
  ACE_TRY_NEW_ENV;
152
 
    {
153
 
      Notify_Test_Client client;
154
 
      client.init (argc, argv ACE_ENV_ARG_PARAMETER);
155
 
      ACE_TRY_CHECK;
156
 
 
157
 
      PortableServer::POA_ptr poa = client.root_poa ();
158
 
 
159
 
      CosNotifyChannelAdmin::EventChannel_var ec =
160
 
               client.create_event_channel ("NotifyEventChannelFactory",
161
 
                                            0
162
 
                                            ACE_ENV_ARG_PARAMETER);
163
 
      ACE_TRY_CHECK;
164
 
 
165
 
      // register control with naming service
166
 
      supplier_ctrl_i controller;
167
 
 
168
 
      CosNaming::Name ctrl_name (1);
169
 
      ctrl_name.length (1);
170
 
      ctrl_name[0].id = CORBA::string_dup ("Supplier");
171
 
 
172
 
      PortableServer::ObjectId_var oid =
173
 
        poa->activate_object (&controller);
174
 
 
175
 
      CosNaming::NamingContext_ptr naming_context =
176
 
                                      client.naming_context ();
177
 
 
178
 
      CORBA::Object_var controller_obj = poa->id_to_reference (oid.in ());
179
 
      naming_context->bind (ctrl_name, controller_obj.in ());
180
 
 
181
 
      int done = 0;
182
 
 
183
 
      CosNotifyChannelAdmin::SupplierAdmin_var admin =
184
 
        create_supplieradmin (ec.in () ACE_ENV_ARG_PARAMETER);
185
 
 
186
 
      if (!CORBA::is_nil (admin.in ()))
187
 
        {
188
 
          create_supplier (admin.in (), client.root_poa () ACE_ENV_ARG_PARAMETER);
189
 
 
190
 
          // Ready. So Write ior to file
191
 
          CORBA::ORB_ptr orb = client.orb ();
192
 
          CORBA::String_var ior = orb->object_to_string (controller_obj.in ());
193
 
          FILE *fd = ACE_OS::fopen (ior_file, "w");
194
 
          if (fd == 0)
195
 
            ACE_ERROR_RETURN ((LM_ERROR,
196
 
                               "Cannot open output file for "
197
 
                               "writing IOR: %s",
198
 
                               ior_file),
199
 
                               1);
200
 
          ACE_OS::fprintf (fd, "%s", ior.in ());
201
 
          ACE_OS::fclose (fd);
202
 
 
203
 
          if (TAO_debug_level)
204
 
            ACE_DEBUG ((LM_DEBUG, "Supplier Ready.\n"));
205
 
 
206
 
          while ((!done) && (n_events > 0))
207
 
            {
208
 
              if (go)
209
 
                {
210
 
                  done = setup_event ();
211
 
                  n_events--;
212
 
                }
213
 
 
214
 
              if (orb->work_pending ())
215
 
                orb->perform_work ();
216
 
            }
217
 
 
218
 
          orb->destroy ();
219
 
        }
220
 
    }
221
 
  ACE_CATCH (CORBA::Exception, e)
222
 
    {
223
 
      ACE_PRINT_EXCEPTION (e, "Supplier Exception: ");
224
 
      status =  1;
225
 
    }
226
 
  ACE_ENDTRY;
227
 
 
228
 
 return status;
229
 
}