summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/benchmark/server.cpp
blob: a8daa980d4a7766019678da0d683987af0d2c3b8 (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
// $Id$


#include "server.h"

Server::Server (void)
  :process_strategy_ (&process_options_)
{
  this->process_options_.command_line ("./child -ORBport 0 -ORBobjrefstyle url");
}

        
// Initializes the mpeg server
int
Server::init (int argc,
              char **argv,
              CORBA::Environment& env)
{
  int result;
  
  // Initialize the orb_manager
  this->orb_manager_.init_child_poa (argc,
                                     argv,
                                     "child_poa",
                                     env);
  TAO_CHECK_ENV_RETURN (env,
                        -1);
  
  CORBA::ORB_var orb = 
    this->orb_manager_.orb ();

  PortableServer::POA_var child_poa = 
    this->orb_manager_.child_poa ();

  // Resolve the Naming service reference. 

  CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService");
  if (CORBA::is_nil (naming_obj.in ()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       " (%P|%t) Unable to resolve the Name Service.\n"),
                      -1);

  this->naming_context_ =
    CosNaming::NamingContext::_narrow (naming_obj.in (),
                                       env);
  TAO_CHECK_ENV_RETURN (env,-1);

  // Register the video mmdevice object with the ORB
  ACE_NEW_RETURN (this->mmdevice_,
                  TAO_MMDevice (&this->process_strategy_),
                  -1);

  // create the video server mmdevice with the naming service pointer.
  this->orb_manager_.activate_under_child_poa ("Bench_Server_MMDevice",
                                               this->mmdevice_,
                                               env);
  TAO_CHECK_ENV_RETURN (env,-1);

  // Register the mmdevice with the naming service.
  CosNaming::Name server_mmdevice_name (1);
  server_mmdevice_name.length (1);
  server_mmdevice_name [0].id = CORBA::string_dup ("Bench_Server_MMDevice");
  
  // Register the video control object with the naming server.
  this->naming_context_->bind (server_mmdevice_name,
                               this->mmdevice_->_this (env),
                               env);

  if (env.exception () != 0)
    {
      env.clear ();
      this->naming_context_->rebind (server_mmdevice_name,
                              this->mmdevice_->_this (env),
                              env);
      TAO_CHECK_ENV_RETURN (env,-1);
    }
  return 0;
}

// Runs the mpeg server
int
Server::run (CORBA::Environment& env)
{
  int result;
  // Run the ORB event loop
  while (1)
    {
      this->orb_manager_.run (env);
      if (errno== EINTR)
        continue;
      else
        break;
    }
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Server::run () "
              "came out of the (ORB) "
              "event loop %p\n",
              "run_event_loop"));
  return 0;
  
}

Server::~Server (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "(%P|%t) Server: Removing handlers from the Reactor\n"));

  if (this->mmdevice_ != 0)
    delete this->mmdevice_;
  
}


int
main (int argc, char **argv)
{
  Server server;
  TAO_TRY
    {
      if (server.init (argc, argv, TAO_TRY_ENV) == -1)
        return 1;
      TAO_CHECK_ENV;

      server.run (TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Bench_Server::Exception");
      return -1;
    }
  TAO_ENDTRY;
  
  return 0;
}