• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 
19 #include "pvmf_node_interface.h"
20 
21 // TODO: Both the info and error handling look very similar, we should
22 // try to refactor them at some point (but beware of the info/error
23 // context difference).
24 
SetState(TPVMFNodeInterfaceState s)25 OSCL_EXPORT_REF void PVMFNodeInterface::SetState(TPVMFNodeInterfaceState s)
26 {
27     iInterfaceState = s;
28     ReportInfoEvent(PVMFInfoStateChanged, (OsclAny*)s);
29 }
30 
ReportCmdCompleteEvent(PVMFSessionId session,const PVMFCmdResp & resp)31 OSCL_EXPORT_REF void PVMFNodeInterface::ReportCmdCompleteEvent(
32     PVMFSessionId session, const PVMFCmdResp& resp)
33 {
34     const unsigned int size = iSessions.size();
35 
36     for (unsigned int i = 0; i < size; ++i)
37     {
38         if (iSessions[i].iId == session)
39         {
40             PVMFNodeCmdStatusObserver *observer = iSessions[i].iInfo.iCmdStatusObserver;
41 
42             if (NULL != observer)
43             {
44                 observer->NodeCommandCompleted(resp);
45             }
46             return;
47         }
48     }
49 }
50 
ReportErrorEvent(PVMFEventType aEventType,OsclAny * aEventData,PVInterface * aExtMsg)51 OSCL_EXPORT_REF void PVMFNodeInterface::ReportErrorEvent(
52     PVMFEventType aEventType, OsclAny* aEventData, PVInterface*aExtMsg)
53 {
54     ReportErrorEvent(PVMFAsyncEvent(PVMFErrorEvent,
55                                     aEventType,
56                                     NULL,  // Error Context will be set below.
57                                     aExtMsg,
58                                     aEventData));
59 }
60 
ReportErrorEvent(const PVMFAsyncEvent & aEvent)61 OSCL_EXPORT_REF void PVMFNodeInterface::ReportErrorEvent(
62     const PVMFAsyncEvent& aEvent)
63 {
64     if (aEvent.IsA() != PVMFErrorEvent)
65     {
66         // TODO: Should log loudly an error here.
67         return;
68     }
69 
70     const unsigned int size = iSessions.size();
71 
72     for (unsigned int i = 0; i < size; ++i)
73     {
74         PVMFNodeErrorEventObserver *observer = iSessions[i].iInfo.iErrorObserver;
75 
76         if (NULL != observer)
77         {
78             PVMFAsyncEvent event(PVMFErrorEvent,
79                                  aEvent.GetEventType(),
80                                  iSessions[i].iInfo.iErrorContext,
81                                  aEvent.GetEventExtensionInterface(),
82                                  aEvent.GetEventData(),
83                                  aEvent.GetLocalBuffer(),
84                                  aEvent.GetLocalBufferSize());
85             observer->HandleNodeErrorEvent(event);
86         }
87     }
88 }
89 
ReportInfoEvent(PVMFEventType aEventType,OsclAny * aEventData,PVInterface * aExtMsg)90 OSCL_EXPORT_REF void PVMFNodeInterface::ReportInfoEvent(
91     PVMFEventType aEventType, OsclAny* aEventData, PVInterface*aExtMsg)
92 {
93     ReportInfoEvent(PVMFAsyncEvent(PVMFInfoEvent,
94                                    aEventType,
95                                    NULL,  // Info Context will be set below.
96                                    aExtMsg,
97                                    aEventData));
98 }
99 
ReportInfoEvent(const PVMFAsyncEvent & aEvent)100 OSCL_EXPORT_REF void PVMFNodeInterface::ReportInfoEvent(
101     const PVMFAsyncEvent& aEvent)
102 {
103     if (aEvent.IsA() != PVMFInfoEvent)
104     {
105         // TODO: Should log loudly an error here.
106         return;
107     }
108 
109     const unsigned int size = iSessions.size();
110 
111     for (unsigned int i = 0; i < size; ++i)
112     {
113         PVMFNodeInfoEventObserver *observer = iSessions[i].iInfo.iInfoObserver;
114 
115         if (NULL != observer)
116         {
117             PVMFAsyncEvent event(PVMFInfoEvent,
118                                  aEvent.GetEventType(),
119                                  iSessions[i].iInfo.iInfoContext,
120                                  aEvent.GetEventExtensionInterface(),
121                                  aEvent.GetEventData(),
122                                  aEvent.GetLocalBuffer(),
123                                  aEvent.GetLocalBufferSize());
124 
125             observer->HandleNodeInformationalEvent(event);
126         }
127     }
128 }
129