TVService does not call all PowerEventHandlers if Reinitialize Server is set

Discussion in '1.0 final and SVN Builds' started by Charly_Brown, February 8, 2009.

  1. Charly_Brown
    • Premium Supporter

    Charly_Brown MP Donator

    Joined:
    December 21, 2008
    Messages:
    19
    Likes Received:
    1
    Gender:
    Male
    Occupation:
    Software Quality Manager
    Location:
    Munich
    Ratings:
    +1 / 0
    Home Country:
    Germany Germany
    TV-Server Version: 1.0 Final
    MediaPortal Version: 1.0 Final
    MediaPortal Skin: Blue3
    Windows Version: Vista Home Premium 32bit SP1
    CPU Type: AMD Phenom X4
    HDD: Samsung 640GB
    Memory: 2GB
    Motherboard: Gigabyte MA78GPM-DS2H
    Video Card: HD3200
    Video Card Driver: Catalyst 8.12
    Sound Card:
    Sound Card AC3:
    Sound Card Driver:
    1. TV Card: Terratec Cinergy DVB-S2 HD
    1. TV Card Type:
    1. TV Card Driver:
    2. TV Card: Terratec Cinergy DVB-S2 HD CI
    2. TV Card Type:
    2. TV Card Driver:
    3. TV Card:
    3. TV Card Type:
    3. TV Card Driver:
    4. TV Card:
    4. TV Card Type:
    4. TV Card Driver:
    MPEG2 Video Codec:
    MPEG2 Audio Codec:
    h.264 Video Codec:
    Satelite/CableTV Provider:
    HTPC Case:
    Cooling:
    Power Supply:
    Remote:
    TV:
    TV - HTPC Connection:

    Hi,

    I faced the same problems as reported in the threads
    Reinitalize Tuner Prevents Scheduled Recording
    and
    TV Problems In Vista


    After downloading the source from subversion I digged through Service1.cs::OnPowerEvent. The routine works fine as long as no reinitialization of the service is requested. In this case the current code calls all entries is the list of powerhandlerevents that are registered to the service. If reinitialization is requested the routine calls at first the powereventhandler of the service and there DeInit() is called. DeInit() causes all plugins to unregister from tvservice. As a consequence powerscheduler also unregisters not only from tvservice but also removes its own powereventhandler from the service. When the powereventhandler of the service returns there is no additional entry left in the list of powereventhandlers and so powerscheduler does not get informed about the shutdown.

    I modified the code to make sure that the list of powereventhandlers is worked through from the last to the first entry. This solves IMHO two problems

    1) The powereventhandler of the service is called as last and therefore all other registered powereventhandlers have been called before and have been executed. So when standby is requested the powerscheduler can set the next wakeup time
    2) If entries of a list are removed, while the program runs through the list, it might be possible that the program flow is interrupted, or parts of the list are not taken into account (At least this I faced when doing some programs in C++ and I guess there is no difference in C# ;) ).



    Okay here is the original code I'm talking about, taken from Service1.cs::OnPowerEvent
    Code (Text):
    1.  
    2.       foreach (PowerEventHandler handler in _powerEventHandlers)
    3.       {
    4.           bool result = handler(powerStatus);
    5.            if (result == false)
    6.            {
    7.              accept = false;
    8.              powerEventPreventers.Add(handler);
    9.            }
    10.            else
    11.              powerEventAllowers.Add(handler);
    12.       }
    13.  
    And this is the modified code, where the list is worked through from the end.
    Code (Text):
    1.  
    2.       for (int i = (_powerEventHandlers.Count - 1); i >= 0; i--)
    3.       {
    4.  
    5.         PowerEventHandler handler = _powerEventHandlers[i];
    6.  
    7.         if (handler(powerStatus) == false)
    8.         {
    9.  
    10.           accept = false;
    11.           powerEventPreventers.Add(handler);
    12.  
    13.         }
    14.         else
    15.  
    16.           powerEventAllowers.Add(handler);
    17.  
    18.       }
    19.  
    20.  
     
    • Like Like x 1
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. ronilse
    • Premium Supporter

    ronilse Retired Team Member

    Joined:
    July 19, 2005
    Messages:
    4,422
    Likes Received:
    280
    Gender:
    Male
    Occupation:
    MediaPortal tester
    Location:
    Moss
    Ratings:
    +280 / 0
    Home Country:
    Norway Norway
    Show System Specs
    Hi,
    Now confirmed & added to Mantis (I got a bit confused since it's 2 threads & early in morning, but now correct one it's updated ;) )

    Link to other thread


    Regards
    Roy
     
  4. ronilse
    • Premium Supporter

    ronilse Retired Team Member

    Joined:
    July 19, 2005
    Messages:
    4,422
    Likes Received:
    280
    Gender:
    Male
    Occupation:
    MediaPortal tester
    Location:
    Moss
    Ratings:
    +280 / 0
    Home Country:
    Norway Norway
    Show System Specs
    Hi,
    With latest SVN this works here now, so please test it & give feedback(also post logs if it doesn't work).

    Regards
    Roy
     
  5. Paranoid Delusion
    • Premium Supporter

    Paranoid Delusion Moderation Manager

    Joined:
    June 13, 2005
    Messages:
    13,062
    Likes Received:
    1,481
    Gender:
    Male
    Occupation:
    Electrical Engineer
    Location:
    Cheshire
    Ratings:
    +1,482 / 0
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    Thanks from me for letting us know :)
     
  6. Charly_Brown
    • Premium Supporter

    Charly_Brown MP Donator

    Joined:
    December 21, 2008
    Messages:
    19
    Likes Received:
    1
    Gender:
    Male
    Occupation:
    Software Quality Manager
    Location:
    Munich
    Ratings:
    +1 / 0
    Home Country:
    Germany Germany
    Tested with new SVN,

    Wakeup Time is now correctly set. :D

    BTW Could someone update the SVN on sf.net :D

    Charly
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!