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