Mercurial > epgrec.yaz
comparison Reservation.class.php @ 165:3d4df1fe4166
merged with upstream
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Thu, 08 Apr 2010 04:22:20 +0900 |
| parents | 66eabfc1b118 84220382fea8 |
| children | 1c4558d1a449 |
comparison
equal
deleted
inserted
replaced
| 160:47a3acf19870 | 165:3d4df1fe4166 |
|---|---|
| 2 include_once('config.php'); | 2 include_once('config.php'); |
| 3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | 3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); |
| 4 include_once( INSTALL_PATH . "/reclib.php" ); | 4 include_once( INSTALL_PATH . "/reclib.php" ); |
| 5 include_once( INSTALL_PATH . "/Settings.class.php" ); | 5 include_once( INSTALL_PATH . "/Settings.class.php" ); |
| 6 include_once( INSTALL_PATH . "/recLog.inc.php" ); | 6 include_once( INSTALL_PATH . "/recLog.inc.php" ); |
| 7 | |
| 8 // 後方互換性 | |
| 9 if( !defined( "RECORDER_CMD" ) ) { | |
| 10 define( "RECORDER_CMD", INSTALL_PATH."/recorder.php" ); | |
| 11 } | |
| 7 | 12 |
| 8 | 13 |
| 9 // 予約クラス | 14 // 予約クラス |
| 10 | 15 |
| 11 class Reservation { | 16 class Reservation { |
| 286 ); | 291 ); |
| 287 | 292 |
| 288 // ATで予約する | 293 // ATで予約する |
| 289 $process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env ); | 294 $process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env ); |
| 290 if( is_resource( $process ) ) { | 295 if( is_resource( $process ) ) { |
| 291 fwrite($pipes[0], $settings->sleep." ".$sleep_time."\n" ); | 296 fwrite($pipes[0], RECORDER_CMD." ".$rrec->id."\n" ); |
| 292 fwrite($pipes[0], DO_RECORD . "\n" ); | |
| 293 fwrite($pipes[0], COMPLETE_CMD." ".$rrec->id."\n" ); | |
| 294 if( $settings->use_thumbs == 1 ) { | |
| 295 fwrite($pipes[0], $gen_thumbnail."\n" ); | |
| 296 } | |
| 297 fclose($pipes[0]); | 297 fclose($pipes[0]); |
| 298 // 標準エラーを取る | 298 // 標準エラーを取る |
| 299 $rstring = stream_get_contents( $pipes[2]); | 299 $rstring = stream_get_contents($pipes[2]); |
| 300 | 300 |
| 301 fclose( $pipes[2] ); | 301 fclose( $pipes[2] ); |
| 302 fclose( $pipes[1] ); | |
| 302 proc_close( $process ); | 303 proc_close( $process ); |
| 303 } | 304 } |
| 304 else { | 305 else { |
| 305 $rrec->delete(); | 306 $rrec->delete(); |
| 306 reclog( "Reservation::custom atの実行に失敗した模様", EPGREC_ERROR); | 307 reclog( "Reservation::custom atの実行に失敗した模様", EPGREC_ERROR); |
| 352 } | 353 } |
| 353 if( $rec == null ) { | 354 if( $rec == null ) { |
| 354 throw new Exception("IDの指定が無効です"); | 355 throw new Exception("IDの指定が無効です"); |
| 355 } | 356 } |
| 356 if( ! $rec->complete ) { | 357 if( ! $rec->complete ) { |
| 357 // 未実行の予約である | |
| 358 if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) { | 358 if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) { |
| 359 reclog("Reservation::cancel 未実行の予約の取り消しが実行された", EPGREC_ERROR ); | 359 reclog("Reservation::cancel 実行中の予約ID".$rec->id."の取り消しが実行された" ); |
| 360 throw new Exception("未実行の予約です"); | 360 |
| 361 } | 361 // recorderとの通信を試みる |
| 362 exec( $settings->atrm . " " . $rec->job ); | 362 $ipc_key = ftok( RECORDER_CMD, "R" ); |
| 363 reclog("Reservation::cancel ジョブ番号".$rec->job."を削除"); | 363 |
| 364 } | 364 /* php 5.3以降じゃないとmsg_queue_existsは使えない |
| 365 $rec->delete(); | 365 if( ! msg_queue_exists( $ipc_key ) ) { |
| 366 // メッセージキューがない | |
| 367 reclog( "Reservation::cancel 実行中と推測される予約".$rec->id."が実行されていない", EPGREC_ERROR ); | |
| 368 $rec->complete = 1; | |
| 369 throw new RecException( "Reserve:: 実行中と推測される予約が実行されていません。再度、削除を試みてください。", EPGREC_ERROR ); | |
| 370 } | |
| 371 else { | |
| 372 */ | |
| 373 $msgh_r = msg_get_queue( $ipc_key ); | |
| 374 $ipc_key = ftok( RECORDER_CMD, "W" ); | |
| 375 $msgh_w = msg_get_queue( $ipc_key ); | |
| 376 | |
| 377 // 終了を指示 | |
| 378 msg_send( $msgh_r, (int)$rec->id, "terminate" ); | |
| 379 sleep(1); | |
| 380 for( $i = 0; $i < 60; $i++ ) { | |
| 381 $r = msg_receive($msgh_w, (int)$rec->id , $msgtype, 1024, $message, TRUE, MSG_IPC_NOWAIT | MSG_NOERROR); | |
| 382 if( $r ) { | |
| 383 if( $message == "success" ) { | |
| 384 reclog( "Reserve:: 実行中の予約ID".$rec->id."の取り消しに成功した模様" ); | |
| 385 break; | |
| 386 } | |
| 387 else if( $message == "error" ){ | |
| 388 reclog( "Reserve:: 実行中の予約ID".$rec->id."の取り消しに失敗", EPGREC_ERROR ); | |
| 389 throw new RecException("実行中の予約取り消しに失敗しました。しばらく時間をおいてから再度、取り消してください", EPGREC_ERROR ); | |
| 390 } | |
| 391 // それ以外のメッセージは無視して待つ | |
| 392 } | |
| 393 sleep(1); | |
| 394 } | |
| 395 if( $i >= 60 ) throw new RecException("実行中の予約取り消しに失敗しました。しばらく時間をおいてから再度、取り消してください", EPGREC_ERROR ); | |
| 396 // } | |
| 397 } | |
| 398 else { | |
| 399 // まだ実行されていない予約ならatを削除しとく | |
| 400 exec( $settings->atrm . " " . $rec->job ); | |
| 401 reclog("Reservation::cancel ジョブ番号".$rec->job."を削除"); | |
| 402 $rec->delete(); | |
| 403 } | |
| 404 } | |
| 405 else { | |
| 406 // 録画済み予約ならただ消す | |
| 407 $rec->delete(); | |
| 408 } | |
| 366 } | 409 } |
| 367 catch( Exception $e ) { | 410 catch( Exception $e ) { |
| 368 reclog("Reservation::cancel 予約キャンセルでDB接続またはアクセスに失敗した模様", EPGREC_ERROR ); | 411 reclog("Reservation::cancel 予約キャンセルでDB接続またはアクセスに失敗した模様", EPGREC_ERROR ); |
| 369 throw $e; | 412 throw $e; |
| 370 } | 413 } |
