mmserv/sts/stsplayer/src/sts.cpp
changeset 19 4a629bc82c5e
parent 14 80975da52420
equal deleted inserted replaced
14:80975da52420 19:4a629bc82c5e
    15  * This file provides the implementation of System Tone Service used
    15  * This file provides the implementation of System Tone Service used
    16  * by the STS Server.
    16  * by the STS Server.
    17  */
    17  */
    18 
    18 
    19 #include "sts.h"
    19 #include "sts.h"
       
    20 
       
    21 class CSts::CPlayerNode
       
    22     {
       
    23 public:
       
    24     CPlayerNode(CStsPlayer* aPlayer);
       
    25     CPlayerNode(CStsPlayer* aPlayer, MStsPlayAlarmObserver& aObserver);
       
    26     ~CPlayerNode();
       
    27     bool HasObserver();
       
    28     CStsPlayer* Player();
       
    29     MStsPlayAlarmObserver& Observer();
       
    30 private:
       
    31     CStsPlayer* iPlayer;
       
    32     MStsPlayAlarmObserver* iObserver;
       
    33     };
       
    34 
       
    35 CSts::CPlayerNode::CPlayerNode(CStsPlayer* aPlayer) :
       
    36     iPlayer(aPlayer), iObserver(0)
       
    37     {
       
    38     }
       
    39 
       
    40 CSts::CPlayerNode::CPlayerNode(CStsPlayer* aPlayer,
       
    41         MStsPlayAlarmObserver& aObserver) :
       
    42     iPlayer(aPlayer), iObserver(&aObserver)
       
    43     {
       
    44     }
       
    45 
       
    46 CSts::CPlayerNode::~CPlayerNode()
       
    47     {
       
    48     delete iPlayer;
       
    49     }
       
    50 
       
    51 bool CSts::CPlayerNode::HasObserver()
       
    52     {
       
    53     return iObserver != 0;
       
    54     }
       
    55 
       
    56 CStsPlayer* CSts::CPlayerNode::Player()
       
    57     {
       
    58     return iPlayer;
       
    59     }
       
    60 
       
    61 MStsPlayAlarmObserver& CSts::CPlayerNode::Observer()
       
    62     {
       
    63     return *iObserver;
       
    64     }
    20 
    65 
    21 /*static*/CSts* CSts::Create()
    66 /*static*/CSts* CSts::Create()
    22     {
    67     {
    23     CSts* self = new CSts();
    68     CSts* self = new CSts();
    24     if (self != 0)
    69     if (self != 0)
    51 CSts::~CSts()
    96 CSts::~CSts()
    52     {
    97     {
    53     CleanUpPlayers();
    98     CleanUpPlayers();
    54     }
    99     }
    55 
   100 
    56 void CSts::PlayTone(CSystemToneService::TToneType aToneType,
   101 void CSts::PlayTone(CSystemToneService::TToneType aTone)
    57         unsigned int& aPlayToneContext)
       
    58     {
   102     {
    59     CStsPlayer* player = CStsPlayer::Create(*this, aToneType, iNextContext);
   103     CStsPlayer* player = CStsPlayer::CreateTonePlayer(*this, aTone,
       
   104             iNextContext);
    60     if (player != 0)
   105     if (player != 0)
    61         {
   106         {
    62         iMap[iNextContext] = player;
   107         iPlayerMap[iNextContext] = new CPlayerNode(player);
    63         aPlayToneContext = iNextContext;
       
    64         iNextContext++;
   108         iNextContext++;
       
   109         if (iNextContext == 0)
       
   110             iNextContext++;
    65         player->Play();
   111         player->Play();
    66         }
   112         }
    67     else
   113     else
    68         {
   114         {
    69         aPlayToneContext = 0;
   115         //TODO: Add trace here
    70         }
   116         }
    71     }
   117     }
    72 
   118 
    73 void CSts::StopTone(unsigned int aPlayToneContext)
   119 void CSts::PlayAlarm(CSystemToneService::TAlarmType aAlarm,
       
   120         unsigned int& aAlarmContext, MStsPlayAlarmObserver& aObserver)
    74     {
   121     {
    75     CStsPlayer* player = iMap[aPlayToneContext];
   122     CStsPlayer* player = CStsPlayer::CreateAlarmPlayer(*this, aAlarm,
    76     if (player)
   123             iNextContext);
       
   124     if (player != 0)
    77         {
   125         {
    78         player->Stop();
   126         iPlayerMap[iNextContext] = new CPlayerNode(player, aObserver);
    79         PlayToneComplete(aPlayToneContext);
   127         aAlarmContext = iNextContext;
       
   128         iNextContext++;
       
   129         if (iNextContext == 0)
       
   130             iNextContext++;
       
   131         player->Play();
       
   132         }
       
   133     else
       
   134         {
       
   135         //TODO: Add trace here
       
   136         aAlarmContext = 0;
       
   137         }
       
   138     }
       
   139 
       
   140 void CSts::StopAlarm(unsigned int aAlarmContext)
       
   141     {
       
   142     CPlayerNode* node = iPlayerMap[aAlarmContext];
       
   143     iPlayerMap.erase(aAlarmContext);
       
   144     if (node)
       
   145         {
       
   146         node->Player()->Stop();
       
   147         delete node;
       
   148         }
       
   149     else
       
   150         {
       
   151         //TODO: Add trace here
    80         }
   152         }
    81     }
   153     }
    82 
   154 
    83 void CSts::CleanUpPlayers()
   155 void CSts::CleanUpPlayers()
    84     {
   156     {
    85     for (TPlayerMap::iterator i = iMap.begin(); i != iMap.end(); i++)
   157         while (!iPlayerMap.empty())
       
   158             {
       
   159             //TODO: Add trace here
       
   160             StopAlarm(iPlayerMap.begin()->first);
       
   161             }
       
   162     }
       
   163 
       
   164 void CSts::PlayComplete(unsigned int aContext)
       
   165     {
       
   166     CPlayerNode* node = iPlayerMap[aContext];
       
   167     iPlayerMap.erase(aContext);
       
   168     if (node)
    86         {
   169         {
    87         StopTone(i->first);
   170         CStsPlayer* player = node->Player();
       
   171         if (node->HasObserver())
       
   172             {
       
   173             node->Observer().PlayAlarmComplete(aContext);
       
   174             }
       
   175         delete node;
       
   176         }
       
   177     else
       
   178         {
       
   179         // TODO: log unexpected error
    88         }
   180         }
    89     }
   181     }
    90 
       
    91 void CSts::PlayToneComplete(unsigned int aPlayToneContext)
       
    92     {
       
    93     CStsPlayer* player = iMap[aPlayToneContext];
       
    94     iMap[aPlayToneContext] = 0;
       
    95     if (player)
       
    96         {
       
    97         delete player;
       
    98         }
       
    99     }