1cdf0e10cSrcweir#!/usr/bin/perl 2cdf0e10cSrcweir######################################################################### 3cdf0e10cSrcweir 4*7e90fac2SAndrew Rist #************************************************************** 5*7e90fac2SAndrew Rist# 6*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 7*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 8*7e90fac2SAndrew Rist# distributed with this work for additional information 9*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 10*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 11*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 12*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 13*7e90fac2SAndrew Rist# 14*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 15*7e90fac2SAndrew Rist# 16*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 17*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 18*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 20*7e90fac2SAndrew Rist# specific language governing permissions and limitations 21*7e90fac2SAndrew Rist# under the License. 22*7e90fac2SAndrew Rist# 23*7e90fac2SAndrew Rist#************************************************************** 24*7e90fac2SAndrew Rist 25*7e90fac2SAndrew 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