Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / RTScheduling / DT_Spawn / test.cpp
blob24043b9cbd3373a83c6148f01729e11a88f3db69
1 #include "../Scheduler.h"
2 #include "tao/RTScheduling/RTScheduler_Manager.h"
3 #include "tao/ORB.h"
4 #include "Thread_Action.h"
5 #include "ace/Thread_Manager.h"
6 #include "ace/SString.h"
8 int
9 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
11 CORBA::ORB_var orb;
12 RTScheduling::Current_var current;
14 const char * name = 0;
15 CORBA::Policy_ptr sched_param = 0;
16 CORBA::Policy_ptr implicit_sched_param = 0;
18 Test_Thread_Action thread_action;
20 try
22 orb = CORBA::ORB_init (argc,
23 argv);
25 CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");
27 TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());
29 TAO_Scheduler* scheduler;
30 ACE_NEW_RETURN (scheduler,
31 TAO_Scheduler (orb.in ()),
32 -1);
33 RTScheduling::Scheduler_var safe_scheduler = scheduler;
35 manager->rtscheduler (scheduler);
37 CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");
39 current = RTScheduling::Current::_narrow (current_obj.in ());
41 try
43 ACE_DEBUG ((LM_DEBUG,
44 "Invoking DT spawn without calling begin_scheduling_segment...\n"));
46 ACE_CString data ("Harry Potter");
47 RTScheduling::DistributableThread_var dt =
48 current->spawn (&thread_action,
49 const_cast<char *> (data.c_str ()),
50 name,
51 sched_param,
52 implicit_sched_param,
54 0);
56 catch (const CORBA::BAD_INV_ORDER& )
58 ACE_DEBUG ((LM_DEBUG,
59 "Spawn should be in the context of a Scheduling Segment - Expected Exception\n"));
61 catch (const CORBA::Exception& ex)
63 ex._tao_print_exception ("\n");
66 ACE_DEBUG ((LM_DEBUG,
67 "Start - Scheduling Segment...\n"));
69 current->begin_scheduling_segment ("Potter",
70 sched_param,
71 implicit_sched_param);
73 size_t count = 0;
74 RTScheduling::Current::IdType_var id = current->id ();
75 ACE_OS::memcpy (&count,
76 id->get_buffer (),
77 id->length ());
79 ACE_DEBUG ((LM_DEBUG,
80 "The Current DT Guid is %d\n",
81 count));
83 //Initialize data to be passed to the Thread_Action::do method
84 Data spawn_data;
85 spawn_data.data = "Harry Potter";
86 spawn_data.current = RTScheduling::Current::_duplicate (current.in ());
88 ACE_DEBUG ((LM_DEBUG,
89 "Spawning a new DT...\n"));
90 RTScheduling::DistributableThread_var dt =
91 current->spawn (&thread_action,
92 &spawn_data,
93 "Chamber of Secrets",
94 sched_param,
95 implicit_sched_param,
97 0);
99 current->end_scheduling_segment (name);
100 ACE_DEBUG ((LM_DEBUG,
101 "End - Scheduling Segment %d\n",
102 count));
104 ACE_Thread_Manager::instance ()->wait ();
106 orb->destroy ();
108 catch (const CORBA::Exception& ex)
110 ex._tao_print_exception ("Caught Exception\n");
113 return 0;