1*b1cdbd2cSJim Jagielski#!/usr/bin/perl
2*b1cdbd2cSJim Jagielski#########################################################################
3*b1cdbd2cSJim Jagielski
4*b1cdbd2cSJim Jagielski #**************************************************************
5*b1cdbd2cSJim Jagielski#
6*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
7*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
8*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
9*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
10*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
11*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
12*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
13*b1cdbd2cSJim Jagielski#
14*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
15*b1cdbd2cSJim Jagielski#
16*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
17*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
18*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
20*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
21*b1cdbd2cSJim Jagielski#  under the License.
22*b1cdbd2cSJim Jagielski#
23*b1cdbd2cSJim Jagielski#**************************************************************
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski####################################################################
28*b1cdbd2cSJim Jagielski# File Name: template.pl
29*b1cdbd2cSJim Jagielski# Version  : 1.0
30*b1cdbd2cSJim Jagielski# Project  : XMerge
31*b1cdbd2cSJim Jagielski# Author   : Brian Cameron
32*b1cdbd2cSJim Jagielski# Date	   : 5th Sept. 2001
33*b1cdbd2cSJim Jagielski#
34*b1cdbd2cSJim Jagielski#
35*b1cdbd2cSJim Jagielski# Takes x and y from the command line and taps the screen there.
36*b1cdbd2cSJim Jagielski# Assumes pose is already running.
37*b1cdbd2cSJim Jagielski#
38*b1cdbd2cSJim Jagielski##########################################################################
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielskiuse POSIX "sys_wait_h";   # Need this for waitpid with WNOHANG
41*b1cdbd2cSJim Jagielskiuse EmRPC;  # EmRPC::OpenConnection, CloseConnection
42*b1cdbd2cSJim Jagielskiuse EmFunctions;
43*b1cdbd2cSJim Jagielskiuse EmUtils;
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielskiif ($#ARGV != 0)
46*b1cdbd2cSJim Jagielski{
47*b1cdbd2cSJim Jagielski  print "\nUsage: $0 timeout\n\n";
48*b1cdbd2cSJim Jagielski  exit -1;
49*b1cdbd2cSJim Jagielski}
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski$timeout = $ARGV[0];
52*b1cdbd2cSJim Jagielski
53*b1cdbd2cSJim Jagielskiif (!defined($up_pid = fork()))
54*b1cdbd2cSJim Jagielski{
55*b1cdbd2cSJim Jagielski   print "ERROR, problem forking.\n"
56*b1cdbd2cSJim Jagielski}
57*b1cdbd2cSJim Jagielskielsif ($up_pid)
58*b1cdbd2cSJim Jagielski{
59*b1cdbd2cSJim Jagielski   print "\nChecking to see if pose is started properly.\n";
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski   # Parent process
62*b1cdbd2cSJim Jagielski   #
63*b1cdbd2cSJim Jagielski   sleep($timeout);
64*b1cdbd2cSJim Jagielski
65*b1cdbd2cSJim Jagielski   waitpid($up_pid, WNOHANG);
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski   if (kill(0, $up_pid))
68*b1cdbd2cSJim Jagielski   {
69*b1cdbd2cSJim Jagielski      print "Pose did not start successfully...\n";
70*b1cdbd2cSJim Jagielski      kill(9, $up_pid);
71*b1cdbd2cSJim Jagielski      exit(-1);
72*b1cdbd2cSJim Jagielski   }
73*b1cdbd2cSJim Jagielski   else
74*b1cdbd2cSJim Jagielski   {
75*b1cdbd2cSJim Jagielski      # The child process exited okay, so we know it will not
76*b1cdbd2cSJim Jagielski      # hang...but the open_connection will just die if pose
77*b1cdbd2cSJim Jagielski      # isn't started...so try it in the parent.
78*b1cdbd2cSJim Jagielski      #
79*b1cdbd2cSJim Jagielski      open_connection();
80*b1cdbd2cSJim Jagielski      close_connection();
81*b1cdbd2cSJim Jagielski
82*b1cdbd2cSJim Jagielski      print "Verified pose started successfully...\n";
83*b1cdbd2cSJim Jagielski      exit(0);
84*b1cdbd2cSJim Jagielski   }
85*b1cdbd2cSJim Jagielski}
86*b1cdbd2cSJim Jagielskielse
87*b1cdbd2cSJim Jagielski{
88*b1cdbd2cSJim Jagielski   # Child process - Try to open/close the connection.  This
89*b1cdbd2cSJim Jagielski   # can hang if pose did not start properly...
90*b1cdbd2cSJim Jagielski   #
91*b1cdbd2cSJim Jagielski   open_connection();
92*b1cdbd2cSJim Jagielski   close_connection();
93*b1cdbd2cSJim Jagielski}
94*b1cdbd2cSJim Jagielski
95*b1cdbd2cSJim Jagielskisub open_connection
96*b1cdbd2cSJim Jagielski{
97*b1cdbd2cSJim Jagielski  print "opening connection\n";
98*b1cdbd2cSJim Jagielski  EmRPC::OpenConnection(6415, "localhost");
99*b1cdbd2cSJim Jagielski}
100*b1cdbd2cSJim Jagielski
101*b1cdbd2cSJim Jagielskisub close_connection
102*b1cdbd2cSJim Jagielski{
103*b1cdbd2cSJim Jagielski  print "closing connection\n";
104*b1cdbd2cSJim Jagielski  EmRPC::CloseConnection();
105*b1cdbd2cSJim Jagielski}
106*b1cdbd2cSJim Jagielski
107