summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rddb/rddb.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index 34403d6..b2fedf4 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -148,6 +148,24 @@ type getShowCartListRequest struct {
response chan<- getShowCartListResult
}
+type JingleListEntry struct {
+ Description string
+ ActiveCart int
+ InactiveCart int
+}
+
+type JingleList map[string]JingleListEntry
+
+type getJingleListResult struct {
+ jingles JingleList
+ err error
+}
+
+type getJingleListRequest struct {
+ username string
+ response chan<- getJingleListResult
+}
+
type DB struct {
conf *config
dbh *sql.DB
@@ -167,6 +185,8 @@ type DB struct {
getShowCartListChan chan getShowCartListRequest
getCartInfoStmt *sql.Stmt
getCutInfoStmt *sql.Stmt
+ getJingleListChan chan getJingleListRequest
+ getJingleListStmt *sql.Stmt
quit chan bool
done chan bool
}
@@ -214,6 +234,9 @@ func (db *DB) init() (err error) {
if db.getCutInfoStmt, err = db.dbh.Prepare("select CUT_NAME, EVERGREEN, DESCRIPTION, LENGTH, ORIGIN_DATETIME, PLAY_COUNTER, LAST_PLAY_DATETIME from CUTS where CART_NUMBER = ?"); err != nil {
return
}
+ if db.getJingleListStmt, err = db.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
+ return
+ }
return
}
@@ -351,6 +374,9 @@ func (db *DB) getShowList(username string) (result getShowListResult) {
if result.err = rows.Scan(&show.Title, &macros, &show.ID, &params, &show.lowCart, &show.highCart); result.err != nil {
return
}
+ if params[0] != 'S' {
+ continue
+ }
show.log = showMacroRe.FindStringSubmatch(macros)[1]
result.shows[show.ID] = show
}
@@ -432,6 +458,30 @@ func (db *DB) getShowCartList(show ShowListEntry) (result getShowCartListResult)
return
}
+func (db *DB) getJingleList(username string) (result getJingleListResult) {
+ var rows *sql.Rows
+ if rows, result.err = db.getJingleListStmt.Query(username, dropboxPseudoStation); result.err != nil {
+ return
+ }
+ defer rows.Close()
+
+ result.jingles = make(map[string]JingleListEntry)
+ for rows.Next() {
+ var jingle JingleListEntry
+ var name, params string
+
+ if result.err = rows.Scan(&name, &params, &jingle.ActiveCart, &jingle.InactiveCart, &jingle.Description); result.err != nil {
+ return
+ }
+ if params[0] != 'J' {
+ continue
+ }
+ result.jingles[name] = jingle
+ }
+ result.err = rows.Err()
+ return
+}
+
func (db *DB) dispatchRequests() {
defer func() { db.done <- true }()
for {
@@ -452,6 +502,8 @@ func (db *DB) dispatchRequests() {
req.response <- db.getShowList(req.username)
case req := <-db.getShowCartListChan:
req.response <- db.getShowCartList(req.show)
+ case req := <-db.getJingleListChan:
+ req.response <- db.getJingleList(req.username)
}
}
}
@@ -467,6 +519,7 @@ type DBChan struct {
getMusicInfoChan chan<- getMusicInfoRequest
getShowListChan chan<- getShowListRequest
getShowCartListChan chan<- getShowCartListRequest
+ getJingleListChan chan<- getJingleListRequest
}
func (db *DBChan) GetPassword(username string, cached bool) (string, error) {
@@ -595,6 +648,20 @@ func (db *DBChan) GetShowCartList(show ShowListEntry) ([]CartListEntry, error) {
return res.carts, nil
}
+func (db *DBChan) GetJingleList(username string) (JingleList, error) {
+ resCh := make(chan getJingleListResult)
+ req := getJingleListRequest{}
+ req.username = username
+ req.response = resCh
+ db.getJingleListChan <- req
+
+ res := <-resCh
+ if res.err != nil {
+ return nil, res.err
+ }
+ return res.jingles, nil
+}
+
func (db *DB) GetInterface() *DBChan {
ch := &DBChan{}
ch.getPasswordChan = db.getPasswordChan
@@ -604,6 +671,7 @@ func (db *DB) GetInterface() *DBChan {
ch.getMusicInfoChan = db.getMusicInfoChan
ch.getShowListChan = db.getShowListChan
ch.getShowCartListChan = db.getShowCartListChan
+ ch.getJingleListChan = db.getJingleListChan
return ch
}
@@ -640,6 +708,9 @@ func (db *DB) Cleanup() {
if db.getCutInfoStmt != nil {
db.getCutInfoStmt.Close()
}
+ if db.getJingleListStmt != nil {
+ db.getJingleListStmt.Close()
+ }
}
func NewDB(configfile string) (db *DB, err error) {
@@ -657,6 +728,7 @@ func NewDB(configfile string) (db *DB, err error) {
db.getMusicInfoChan = make(chan getMusicInfoRequest, 10)
db.getShowListChan = make(chan getShowListRequest, 10)
db.getShowCartListChan = make(chan getShowCartListRequest, 10)
+ db.getJingleListChan = make(chan getJingleListRequest, 10)
if err = db.init(); err != nil {
return