緑のボタンを押せ! Press the green button

緑のボタンを押せ! Press the green button

PR

×

Keyword Search

▼キーワード検索

Archives

2026.10
2026.09
2026.08
2026.07
2026.06

Comments

effelpist@ kilovermek.es effelpist &lt;a href=&quot; <small> <a href="http…
Jun@ Re:「いっちゅう」さんのiEPG用ソフト入れてみた(09/15) TVdeIEPG Ver.1.2.1.0がリンク切れしてい…
スター@ Re:hauppauge HD PVR 速報(08/25) スタービーチ <small> <a href="http://c…
ASOBO@ Re:hauppauge HD PVR 速報 ASOBO攻略 <small> <a href="http:/…
ハッピーメール@ Re:hauppauge HD PVR 速報 ハッピーメール <small> <a href="http:/…

Freepage List

Favorite Blog

まだ登録されていません
2009.05.13
XML
テーマ: 私のPC生活(7590)
カテゴリ: PVR

iEPGD関連が終わったところまでで、意外に行数を喰ってしまいました。全体で500行以下はさすがにむりかな…

 (Rubyの言語レベルの)マルチスレッドに対応するために、排他制御も含めましたが、どうもmutexではしっくりいかないので、monitorクラスをmixinして、排他制御は片っ端から、synchronize()を使うという、力技というか、エレファントな感じになってしまいました。(ま、動けばいい、ということで・・・)

#
# Class ReserveDB (C)2009 B.O.
#  refer below for MonitorMixin
#    http://www.ruby-lang.org/ja/man/html/MonitorMixin.html
require( "monitor")
require( "IEPGD")

class ReserveDB
  @@EXT = "tvpid"
  def initialize( workFolder )
    @workFolder = File::expand_path( workFolder)
    self.extend(MonitorMixin)
    if ! FileTest::directory?( @workFolder)
      Dir::mkdir( @workFolder )
    end
  end #def initialize

  def to_s
    "ReserveDB[#{@workFolder}]"
  end #def to_s

  def clear
    synchronize {
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        File.delete( f )
      }
    }
  end #def clear

  def length
    synchronize {
      i = 0
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        i+= 1
      }
      return i
    }
  end # def length

  def empty?
    length() == 0
  end #def empty?

  # adding an iEPGD data
  # needs to check if the same program has existed already
  def push( iEPGo )
    synchronize {
      hash = Hash.new
      del( iEPGo)
      fname = iEPGo.to_s("%D__%T_%eT_%program-title:_%station-name:_%station:.#{@@EXT}" )
      fh = File.open("#{@workFolder}/#{fname}",'w')
      fh.puts( iEPGo.to_s )
      fh.close
    }
  end # def push( iEPG )

  # delete
  # if successful, returns true
  # if not returns nil
  def del( iEPGo )
    hash = Hash.new
    ret = false
    # gather all data in the DB
    synchronize {
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        if (arrayiEPG= IEPG.File2Array( f)) != nil # in this case, if not nil, length must be 1
          if arrayiEPG[0].sameProgram?( iEPGo )
            File.delete( f )
            ret = true
          end
        end
      }
    }
    return ret
  end # def _del( oiEPG )

  def top
    if empty?
      retrun nil
    end
    hash = Hash.new
    ar = Array.new
    synchronize {
      # gather all data in the DB
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        if (arrayiEPG= IEPG.File2Array( f)) != nil
            ar += arrayiEPG
        end
      }
    }
    ar.sort!
    return ar[0]
  end # def top

  def pop
    synchronize {
      if (tmp = top()) == nil
        return nil
      else
        del( tmp )
        return tmp
      end
    }
  end #def pop

end # class ReserveDB < Array






お気に入りの記事を「いいね!」で応援しよう

Last updated  2009.05.13 15:35:52
コメント(0) | コメントを書く


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x
X

© Rakuten Group, Inc.
X
Design a Mobile Site
スマートフォン版を閲覧 | PC版を閲覧
Share by: