summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/mpeg/source/server/as.cpp
blob: 9498800c03ce57bade848fc6f7acf1662c7b95a7 (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
// $Id$

#include "mpeg_server/Audio_Server.h"

int
main (int argc,char **argv)
{
  Audio_Server audio_server;

  //  ACE_DEBUG ((LM_DEBUG, "(%P|%t) %s:%d\n", __FILE__, __LINE__));
  
  TAO_TRY
    {
      // Parses the arguments, and initializes the server.
      if (audio_server.init (argc,
                             argv,
                             0,
                             -INET_SOCKET_BUFFER_SIZE,
                             TAO_TRY_ENV) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Audio_Server: init failed\n"),
                          -1);
      
      char sem_str [BUFSIZ];
      pid_t my_pid;
      
      if ((my_pid = ACE_OS::getpid ()) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Unable to get my pid!\n"),
                          -1);
      

      sprintf (sem_str,
               "%s:%d",
               "Audio_Server_Semaphore",
               my_pid);
      ACE_DEBUG ((LM_DEBUG,
                  "(%P|%t) semaphore is %s\n",
                  sem_str));
      // Release the lock on which the server is waiting
      ACE_Process_Semaphore semaphore (0, // 0 means that the semaphore is
                                          // initially locked
                                       sem_str);
                                       
      if (semaphore.release () == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Error releasing semaphore %s: %p\n",
                           sem_str,
                           "semaphore.release ()"),
                          -1);
      //      ACE_DEBUG ((LM_DEBUG, "(%P|%t) %s:%d\n", __FILE__, __LINE__));
      // Increment ACE_SV_Semaphore by one. Dijkstra's V operation,
      // Tannenbaums UP operation.

      // %% potential race condition if the client
      // sends a request before we enter the event loop
      // Runs the reactor event loop.
      audio_server.run (TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception");
      return -1;
    }
  TAO_ENDTRY;
  
  return 0;

}