2011-07-05 00:19:02 +00:00
|
|
|
source /mod/var/mongoose/lib/setup
|
|
|
|
|
|
|
|
if {![exists -proc class ]} { package require oo }
|
|
|
|
if {![exists -proc sqlite3.open ]} { package require sqlite3 }
|
|
|
|
if {![exists -proc settings ]} { require settings.class }
|
|
|
|
|
|
|
|
set rsvdb [sqlite3.open /var/lib/humaxtv/rsv.db]
|
|
|
|
$rsvdb query {attach database '/var/lib/humaxtv/channel.db' as channel}
|
2011-08-22 20:55:06 +00:00
|
|
|
|
|
|
|
if {![file exists /var/lib/humaxtv/rsvp.db]} {
|
|
|
|
file copy /var/lib/humaxtv/rsv.db /var/lib/humaxtv/rsvp.db
|
|
|
|
set tdb [sqlite3.open /var/lib/humaxtv/rsvp.db]
|
|
|
|
$tdb query {drop table TBL_VERSION}
|
|
|
|
$tdb query {alter table TBL_RESERVATION rename to pending}
|
2011-08-29 22:34:26 +00:00
|
|
|
$tdb query {alter table pending add column action int}
|
2011-08-22 20:55:06 +00:00
|
|
|
$tdb query {delete from pending}
|
|
|
|
$tdb close
|
|
|
|
}
|
|
|
|
$rsvdb query {attach database '/var/lib/humaxtv/rsvp.db' as pending}
|
2011-08-31 21:55:39 +00:00
|
|
|
# This is required to upgrade old tables and will be removed in a future
|
|
|
|
# version.
|
|
|
|
catch { $rsvdb query {alter table pending add column action int} }
|
2011-07-05 00:19:02 +00:00
|
|
|
|
|
|
|
class rsv {
|
2011-07-09 20:12:33 +00:00
|
|
|
ulslot -1
|
2011-07-05 00:19:02 +00:00
|
|
|
ersvtype 0
|
|
|
|
hsvc 0
|
|
|
|
nsttime 0
|
2011-07-11 23:29:21 +00:00
|
|
|
szsttime "00000000000000"
|
2011-07-05 00:19:02 +00:00
|
|
|
nduration 0
|
|
|
|
erepeat 0
|
|
|
|
usevtid 0
|
|
|
|
szevtname {}
|
|
|
|
ulPreOffset 0
|
|
|
|
ulPostOffset 0
|
|
|
|
ulProgramId 0
|
|
|
|
ulSeriesId 0
|
|
|
|
ucVolume 0
|
|
|
|
ucInputMode 0
|
|
|
|
usChNum 0
|
|
|
|
ucRecKind 0
|
|
|
|
ucCRIDType 0
|
|
|
|
szCRID {}
|
|
|
|
szFPBRecPath {}
|
|
|
|
szRecordedProgCrid {}
|
|
|
|
szEventToRecord {}
|
|
|
|
aulEventToRecordInfo {}
|
|
|
|
bRecomRsv 0
|
|
|
|
usLastRecordedEvtId 0
|
|
|
|
eReady 0
|
|
|
|
szSvcName {}
|
|
|
|
usLcn 0
|
|
|
|
sort 0
|
2011-08-29 22:34:26 +00:00
|
|
|
action 0
|
2011-07-05 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 20:55:06 +00:00
|
|
|
rsv method clear_ulslot {} {
|
|
|
|
set ulslot -1
|
|
|
|
}
|
|
|
|
|
2011-07-05 18:38:42 +00:00
|
|
|
rsv method name {} {
|
|
|
|
set name [string range $szevtname 1 end]
|
|
|
|
if {[string first "i7" $name] == 0} {
|
|
|
|
set name [string range $name 2 end]
|
2011-07-05 00:19:02 +00:00
|
|
|
}
|
2011-07-05 18:38:42 +00:00
|
|
|
if {$name == ""} {
|
|
|
|
switch $ersvtype {
|
|
|
|
5 { set name "--- Wake-up ---" }
|
|
|
|
6 { set name "--- Sleep ---" }
|
|
|
|
7 { set name "--- Auto Update ---" }
|
2011-08-31 21:47:43 +00:00
|
|
|
11 { set name "--- DSO Event ---" }
|
2011-07-05 18:38:42 +00:00
|
|
|
default { set name "--- Unknown event type $ersvtype ---" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $name
|
|
|
|
}
|
|
|
|
|
|
|
|
rsv method channel_name {} {
|
|
|
|
return [string range $szSvcName 1 end]
|
2011-07-05 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 22:34:26 +00:00
|
|
|
rsv method icon {} {
|
|
|
|
set rsvicon ""
|
|
|
|
switch [$self get ersvtype] {
|
|
|
|
1 { set rsvicon "175_1_00_Reservation_Watch.png" }
|
|
|
|
2 { set rsvicon "175_1_00_Reservation_Watch.png" }
|
|
|
|
3 { set rsvicon "175_1_11_Reservation_Record.png" }
|
|
|
|
5 { set rsvicon "745_1_10_Video_2Live.png" }
|
|
|
|
6 { set rsvicon "745_1_11_Video_1REC.png" }
|
|
|
|
7 { set rsvicon "345_6_08_ST_Ad_Hoc.png" }
|
|
|
|
}
|
|
|
|
return $rsvicon
|
|
|
|
}
|
|
|
|
|
|
|
|
rsv method RKIcon {} {
|
|
|
|
if {[$self get ucRecKind] == 4} {
|
|
|
|
set RKIcon "175_1_11_Series_Record.png"
|
|
|
|
} else {
|
|
|
|
switch [$self get erepeat] {
|
|
|
|
1 {set RKIcon "521_1_00_RP_Daily_C.png"}
|
|
|
|
2 {set RKIcon "521_1_00_RP_Weekly_C.png"}
|
|
|
|
3 {set RKIcon "521_1_00_RP_Weekdays_C.png"}
|
|
|
|
4 {set RKIcon "521_1_00_RP_Weekend_C.png"}
|
|
|
|
default {set RKIcon ""}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $RKIcon
|
|
|
|
}
|
|
|
|
|
|
|
|
rsv method set_delete {} {
|
|
|
|
set action 1
|
|
|
|
}
|
|
|
|
|
|
|
|
rsv method remove_pending {} {
|
|
|
|
$::rsvdb query "delete from pending where ulslot = [$self get ulslot]"
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:33:19 +00:00
|
|
|
rsv method fix_hsvc {} {
|
|
|
|
global rsvdb
|
|
|
|
|
2011-09-01 22:20:53 +00:00
|
|
|
set _hsvc [$rsvdb query {
|
2011-07-07 22:33:19 +00:00
|
|
|
select hSvc
|
|
|
|
from channel.TBL_SVC
|
2011-09-01 22:20:53 +00:00
|
|
|
where szSvcName = '%s'
|
|
|
|
or szSvcname = '\025%s'
|
2011-07-07 22:33:19 +00:00
|
|
|
limit 1
|
2011-09-01 22:20:53 +00:00
|
|
|
} $szSvcName $szSvcName]
|
2011-07-07 22:33:19 +00:00
|
|
|
|
|
|
|
if {[llength $_hsvc] == 1} {
|
|
|
|
set hsvc [lindex [lindex $_hsvc 0] 1]
|
|
|
|
} else {
|
|
|
|
set hsvc 0
|
|
|
|
}
|
|
|
|
return $hsvc
|
|
|
|
}
|
|
|
|
|
2011-08-22 20:55:06 +00:00
|
|
|
rsv method insert {{table pending}} {
|
2011-07-07 22:33:19 +00:00
|
|
|
global rsvdb
|
2011-07-11 23:29:21 +00:00
|
|
|
|
|
|
|
# Find a spare slot.
|
2011-07-09 20:12:33 +00:00
|
|
|
if {$ulslot < 0} {
|
2011-08-22 20:55:06 +00:00
|
|
|
set slotlist [$rsvdb query "
|
|
|
|
select ulslot FROM $table
|
|
|
|
order by ulslot;
|
|
|
|
"]
|
|
|
|
if {[llength $slotlist] > 0} {
|
|
|
|
set slots [lmap i $slotlist {lindex $i 1}]
|
|
|
|
set max [lindex $i end]
|
|
|
|
for {set i 0} {$i < $max} {incr i} {
|
|
|
|
if {$i ni $slots} {
|
|
|
|
set ulslot $i
|
|
|
|
break
|
|
|
|
}
|
2011-07-11 23:29:21 +00:00
|
|
|
}
|
2011-08-22 20:55:06 +00:00
|
|
|
if {$ulslot < 0} { set ulslot $($max + 1) }
|
2011-07-11 23:29:21 +00:00
|
|
|
}
|
2011-08-22 20:55:06 +00:00
|
|
|
if {$ulslot < 0} { set ulslot 0 }
|
2011-07-07 22:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set fields [lsort [$self vars]]
|
|
|
|
|
|
|
|
foreach field {aulEventToRecordInfo szSvcName usLcn sort} {
|
|
|
|
set df [lsearch $fields $field]
|
|
|
|
set fields [lreplace $fields $df $df]
|
|
|
|
}
|
|
|
|
|
2011-08-29 22:34:26 +00:00
|
|
|
if {$table ne "pending"} {
|
|
|
|
set df [lsearch $fields "action"]
|
|
|
|
set fields [lreplace $fields $df $df]
|
|
|
|
}
|
|
|
|
|
2011-07-07 22:33:19 +00:00
|
|
|
set vals {}
|
|
|
|
foreach field $fields {
|
2011-07-09 20:12:33 +00:00
|
|
|
# Escape any quotes embedded in the data.
|
|
|
|
regsub -all {'} [$self get $field] {''} f
|
|
|
|
lappend vals "'$f'"
|
|
|
|
#lappend vals "'[$self get $field]'"
|
2011-07-07 22:33:19 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 20:55:06 +00:00
|
|
|
set query "insert into ${table}("
|
2011-07-07 22:33:19 +00:00
|
|
|
append query [join $fields ","]
|
|
|
|
append query ") values("
|
|
|
|
append query [join $vals ","]
|
|
|
|
append query ");"
|
|
|
|
|
|
|
|
$rsvdb query $query
|
2011-07-05 22:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 20:55:06 +00:00
|
|
|
proc {rsv list} {{table tbl_reservation}} {
|
|
|
|
set res [$::rsvdb query "
|
|
|
|
select $table.*,
|
2011-07-05 00:19:02 +00:00
|
|
|
channel.TBL_SVC.szSvcName, channel.TBL_SVC.usLcn,
|
|
|
|
case when ersvtype > 3 then 1 else 0 end as sort
|
2011-08-22 20:55:06 +00:00
|
|
|
from $table
|
2011-07-05 00:19:02 +00:00
|
|
|
left join channel.TBL_SVC
|
2011-08-22 20:55:06 +00:00
|
|
|
on $table.hSvc = channel.TBL_SVC.hSvc
|
2011-07-05 00:19:02 +00:00
|
|
|
order by sort, nsttime
|
2011-08-22 20:55:06 +00:00
|
|
|
"]
|
2011-07-05 00:19:02 +00:00
|
|
|
|
|
|
|
set records {}
|
|
|
|
foreach rec $res {
|
|
|
|
lappend records [rsv new $rec]
|
|
|
|
}
|
|
|
|
|
|
|
|
return $records
|
|
|
|
}
|
|
|
|
|
2011-07-11 23:29:21 +00:00
|
|
|
proc {rsv lookuptab} {} {
|
|
|
|
set records {}
|
2011-08-22 20:55:06 +00:00
|
|
|
foreach tab {tbl_reservation pending} {
|
|
|
|
set res [$::rsvdb query "
|
|
|
|
select $tab.szCRID, channel.TBL_SVC.hSvc
|
|
|
|
from $tab left join channel.TBL_SVC
|
|
|
|
on $tab.hSvc = channel.TBL_SVC.hSvc
|
|
|
|
where ersvtype <= 3
|
|
|
|
"]
|
|
|
|
|
|
|
|
foreach rec $res {
|
|
|
|
lappend records "$rec(hSvc)/[file tail $rec(szCRID)]"
|
|
|
|
}
|
2011-07-11 23:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $records
|
|
|
|
}
|
|
|
|
|
2011-08-22 20:55:06 +00:00
|
|
|
proc {rsv entry} {{table TBL_RESERVATION} crid svc} {
|
|
|
|
set res [$::rsvdb query "
|
|
|
|
select $table.*,
|
2011-07-11 23:29:21 +00:00
|
|
|
channel.TBL_SVC.szSvcName, channel.TBL_SVC.usLcn
|
2011-08-22 20:55:06 +00:00
|
|
|
from $table
|
2011-07-11 23:29:21 +00:00
|
|
|
left join channel.TBL_SVC
|
2011-08-22 20:55:06 +00:00
|
|
|
on $table.hSvc = channel.TBL_SVC.hSvc
|
|
|
|
where szCRID like '%%%s' and $table.hsvc = '%s'
|
|
|
|
" $crid $svc]
|
2011-07-11 23:29:21 +00:00
|
|
|
|
|
|
|
if {[llength $res] > 0} {
|
|
|
|
return [rsv new [lindex $res 0]]
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-09-02 19:50:10 +00:00
|
|
|
proc {rsv fetch} {{table TBL_RESERVATION} ersvtype hsvc nsttime usevtid events} {
|
2011-08-31 21:47:43 +00:00
|
|
|
set res [$::rsvdb query "
|
|
|
|
select $table.*,
|
|
|
|
channel.TBL_SVC.szSvcName, channel.TBL_SVC.usLcn
|
|
|
|
from $table
|
|
|
|
left join channel.TBL_SVC
|
|
|
|
on $table.hSvc = channel.TBL_SVC.hSvc
|
2011-09-02 19:50:10 +00:00
|
|
|
where $table.ersvtype = '%s'
|
|
|
|
and $table.hsvc = '%s'
|
2011-08-31 21:47:43 +00:00
|
|
|
and $table.nsttime = '%s'
|
|
|
|
and $table.usevtid = '%s'
|
|
|
|
and $table.szEventToRecord = '%s'
|
2011-09-02 19:50:10 +00:00
|
|
|
" $ersvtype $hsvc $nsttime $usevtid $events]
|
2011-08-31 21:47:43 +00:00
|
|
|
|
|
|
|
if {[llength $res] > 0} {
|
|
|
|
return [rsv new [lindex $res 0]]
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-08-29 22:34:26 +00:00
|
|
|
proc {rsv slot} {{table TBL_RESERVATION} slot} {
|
|
|
|
set res [$::rsvdb query "
|
|
|
|
select $table.*,
|
|
|
|
channel.TBL_SVC.szSvcName, channel.TBL_SVC.usLcn
|
|
|
|
from $table
|
|
|
|
left join channel.TBL_SVC
|
|
|
|
on $table.hSvc = channel.TBL_SVC.hSvc
|
|
|
|
where ulslot = %s" $slot]
|
|
|
|
|
|
|
|
if {[llength $res] > 0} {
|
|
|
|
return [rsv new [lindex $res 0]]
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-07-05 00:19:02 +00:00
|
|
|
proc {rsv cleanup} {} {
|
|
|
|
catch {$::rsvdb close}
|
|
|
|
}
|
|
|
|
|
2011-08-22 20:55:06 +00:00
|
|
|
proc {rsv commit} {} {
|
|
|
|
$::rsvdb query {begin transaction}
|
|
|
|
foreach rec [rsv list pending] {
|
2011-08-29 22:34:26 +00:00
|
|
|
if {[$rec get action] == 0} {
|
|
|
|
$rec clear_ulslot
|
|
|
|
$rec insert TBL_RESERVATION
|
|
|
|
}
|
2011-08-22 20:55:06 +00:00
|
|
|
}
|
|
|
|
$::rsvdb query {delete from pending}
|
|
|
|
$::rsvdb query {commit transaction}
|
|
|
|
}
|
|
|
|
|