Mercurial > epgrec.yaz
diff Reservation.class.php @ 161:84220382fea8
mod: 録画中のキャンセルを可能にした(動作確認、まだ不完全かも)
author | epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp> |
---|---|
date | Sun, 04 Apr 2010 17:10:17 +0900 |
parents | 5b192e94f49d |
children | 3d4df1fe4166 e379552d084c |
line wrap: on
line diff
--- a/Reservation.class.php Tue Mar 30 19:00:39 2010 +0900 +++ b/Reservation.class.php Sun Apr 04 17:10:17 2010 +0900 @@ -5,6 +5,11 @@ include_once( INSTALL_PATH . "/Settings.class.php" ); include_once( INSTALL_PATH . "/recLog.inc.php" ); +// 緇剛 +if( !defined( "RECORDER_CMD" ) ) { + define( "RECORDER_CMD", INSTALL_PATH."/recorder.php" ); +} + // 篋膣 @@ -288,17 +293,13 @@ // ATт膣 $process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env ); if( is_resource( $process ) ) { - fwrite($pipes[0], $settings->sleep." ".$sleep_time."\n" ); - fwrite($pipes[0], DO_RECORD . "\n" ); - fwrite($pipes[0], COMPLETE_CMD." ".$rrec->id."\n" ); - if( $settings->use_thumbs == 1 ) { - fwrite($pipes[0], $gen_thumbnail."\n" ); - } + fwrite($pipes[0], RECORDER_CMD." ".$rrec->id."\n" ); fclose($pipes[0]); // 罔羣若 - $rstring = stream_get_contents( $pipes[2]); + $rstring = stream_get_contents($pipes[2]); fclose( $pipes[2] ); + fclose( $pipes[1] ); proc_close( $process ); } else { @@ -354,15 +355,57 @@ throw new Exception("ID絎≦鴻с"); } if( ! $rec->complete ) { - // 絎茵篋膣с if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) { - reclog("Reservation::cancel 絎茵篋膣羔絎茵", EPGREC_ERROR ); - throw new Exception("絎茵篋膣с"); + reclog("Reservation::cancel 絎茵筝篋膣ID".$rec->id."羔絎茵" ); + + // recorder篆<荅帥 + $ipc_key = ftok( RECORDER_CMD, "R" ); + + /* php 5.3篁ラmsg_queue_exists篏帥 + if( ! msg_queue_exists( $ipc_key ) ) { + // <祉若吾ャ若 + reclog( "Reservation::cancel 絎茵筝ィ羝篋膣".$rec->id."絎茵", EPGREC_ERROR ); + $rec->complete = 1; + throw new RecException( "Reserve:: 絎茵筝ィ羝篋膣絎茵障綺ゃ荅帥", EPGREC_ERROR ); + } + else { + */ + $msgh_r = msg_get_queue( $ipc_key ); + $ipc_key = ftok( RECORDER_CMD, "W" ); + $msgh_w = msg_get_queue( $ipc_key ); + + // 腟篋腓 + msg_send( $msgh_r, (int)$rec->id, "terminate" ); + sleep(1); + for( $i = 0; $i < 60; $i++ ) { + $r = msg_receive($msgh_w, (int)$rec->id , $msgtype, 1024, $message, TRUE, MSG_IPC_NOWAIT | MSG_NOERROR); + if( $r ) { + if( $message == "success" ) { + reclog( "Reserve:: 絎茵筝篋膣ID".$rec->id."羔罔≧" ); + break; + } + else if( $message == "error" ){ + reclog( "Reserve:: 絎茵筝篋膣ID".$rec->id."羔紊掩", EPGREC_ERROR ); + throw new RecException("絎茵筝篋膣羔紊掩障違綺羔", EPGREC_ERROR ); + } + // 篁ュ<祉若吾∴緇 + } + sleep(1); + } + if( $i >= 60 ) throw new RecException("絎茵筝篋膣羔紊掩障違綺羔", EPGREC_ERROR ); +// } } - exec( $settings->atrm . " " . $rec->job ); - reclog("Reservation::cancel 吾с".$rec->job.""); + else { + // 障絎茵篋膣atゃ + exec( $settings->atrm . " " . $rec->job ); + reclog("Reservation::cancel 吾с".$rec->job.""); + $rec->delete(); + } } - $rec->delete(); + else { + // 牙紙推膣羔 + $rec->delete(); + } } catch( Exception $e ) { reclog("Reservation::cancel 篋膣c潟祉DB・膓障≪祉鴻紊掩罔≧", EPGREC_ERROR ); @@ -370,4 +413,4 @@ } } } -?> +?> \ No newline at end of file