kodi
PltMicroMediaController.h
1 /*****************************************************************
2 |
3 | Platinum - Micro Media Controller
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
35 #ifndef _MICRO_MEDIA_CONTROLLER_H_
36 #define _MICRO_MEDIA_CONTROLLER_H_
37 
38 /*----------------------------------------------------------------------
39 | includes
40 +---------------------------------------------------------------------*/
41 #include "Platinum.h"
42 #include "PltMediaServer.h"
43 #include "PltSyncMediaBrowser.h"
44 #include "PltMediaController.h"
45 #include "Neptune.h"
46 
47 /*----------------------------------------------------------------------
48 | definitions
49 +---------------------------------------------------------------------*/
52 typedef NPT_Map<NPT_String, NPT_String>::Entry PLT_StringMapEntry;
53 
54 /*----------------------------------------------------------------------
55 | PLT_MediaItemIDFinder
56 +---------------------------------------------------------------------*/
58 {
59 public:
60  // methods
61  PLT_MediaItemIDFinder(const char* object_id) : m_ObjectID(object_id) {}
62 
63  bool operator()(const PLT_MediaObject* const & item) const {
64  return item->m_ObjectID.Compare(m_ObjectID, true) ? false : true;
65  }
66 
67 private:
68  // members
69  NPT_String m_ObjectID;
70 };
71 
72 /*----------------------------------------------------------------------
73 | PLT_MicroMediaController
74 +---------------------------------------------------------------------*/
76  public PLT_MediaController,
78 {
79 public:
81  virtual ~PLT_MicroMediaController();
82 
83  void ProcessCommandLoop();
84 
85  // PLT_MediaBrowserDelegate methods
86  bool OnMSAdded(PLT_DeviceDataReference& device);
87 
88  // PLT_MediaControllerDelegate methods
89  bool OnMRAdded(PLT_DeviceDataReference& device);
90  void OnMRRemoved(PLT_DeviceDataReference& device);
91  void OnMRStateVariablesChanged(PLT_Service* /* service */,
92  NPT_List<PLT_StateVariable*>* /* vars */);
93 
94  // PLT_HttpClientTask method
95  NPT_Result ProcessResponse(NPT_Result res,
96  const NPT_HttpRequest& request,
97  const NPT_HttpRequestContext& context,
98  NPT_HttpResponse* response);
99 
100 private:
101  const char* ChooseIDFromTable(PLT_StringMap& table);
102  void PopDirectoryStackToRoot(void);
103  NPT_Result DoBrowse(const char* object_id = NULL, bool metdata = false);
104 
105  void GetCurMediaServer(PLT_DeviceDataReference& server);
106  void GetCurMediaRenderer(PLT_DeviceDataReference& renderer);
107 
108  PLT_DeviceDataReference ChooseDevice(const NPT_Lock<PLT_DeviceMap>& deviceList);
109 
110  // Command Handlers
111  void HandleCmd_scan(const char* ip);
112  void HandleCmd_getms();
113  void HandleCmd_setms();
114  void HandleCmd_ls();
115  void HandleCmd_info();
116  void HandleCmd_cd(const char* command);
117  void HandleCmd_cdup();
118  void HandleCmd_pwd();
119  void HandleCmd_help();
120  void HandleCmd_getmr();
121  void HandleCmd_setmr();
122  void HandleCmd_download();
123  void HandleCmd_open();
124  void HandleCmd_play();
125  void HandleCmd_seek(const char* command);
126  void HandleCmd_stop();
127  void HandleCmd_mute();
128  void HandleCmd_unmute();
129 
130 private:
131  /* Tables of known devices on the network. These are updated via the
132  * OnMSAddedRemoved and OnMRAddedRemoved callbacks. Note that you should first lock
133  * before accessing them using the NPT_Map::Lock function.
134  */
135  NPT_Lock<PLT_DeviceMap> m_MediaServers;
136  NPT_Lock<PLT_DeviceMap> m_MediaRenderers;
137 
138  /* Currently selected media server as well as
139  * a lock. If you ever want to hold both the m_CurMediaRendererLock lock and the
140  * m_CurMediaServerLock lock, make sure you grab the server lock first.
141  */
142  PLT_DeviceDataReference m_CurMediaServer;
143  NPT_Mutex m_CurMediaServerLock;
144 
145  /* Currently selected media renderer as well as
146  * a lock. If you ever want to hold both the m_CurMediaRendererLock lock and the
147  * m_CurMediaServerLock lock, make sure you grab the server lock first.
148  */
149  PLT_DeviceDataReference m_CurMediaRenderer;
150  NPT_Mutex m_CurMediaRendererLock;
151 
152  /* Most recent results from a browse request. The results come back in a
153  * callback instead of being returned to the calling function, so this
154  * variable is necessary in order to give the results back to the calling
155  * function.
156  */
157  PLT_MediaObjectListReference m_MostRecentBrowseResults;
158 
159  /* When browsing through the tree on a media server, this is the stack
160  * symbolizing the current position in the tree. The contents of the
161  * stack are the object ID's of the nodes. Note that the object id: "0" should
162  * always be at the bottom of the stack.
163  */
164  NPT_Stack<NPT_String> m_CurBrowseDirectoryStack;
165 
166  /* Semaphore on which to block when waiting for a response from over
167  * the network
168  */
169  NPT_SharedVariable m_CallbackResponseSemaphore;
170 
171  /* Task Manager managing download tasks */
172  PLT_TaskManager m_DownloadTaskManager;
173 };
174 
175 #endif /* _MICRO_MEDIA_CONTROLLER_H_ */
176 
Definition: NptHttp.h:566
UPnP AV Media Server.
Definition: NptHttp.h:315
UPnP AV Media Controller synchronous implementation.
Definition: PltMediaController.h:243
Definition: NptHttp.h:282
UPnP Service.
Definition: PltService.h:67
The PLT_TaskManager class maintains a list of runnable tasks.
Definition: PltTaskManager.h:60
Definition: NptThreads.h:76
Definition: NptThreads.h:149
Definition: NptThreads.h:113
Definition: PltMicroMediaController.h:57
Definition: PltMediaController.h:102
Definition: PltMicroMediaController.h:75
The PLT_MediaObject class is any data entity that can be returned by a ContentDirectory Service from ...
Definition: PltMediaItem.h:217
Definition: NptStrings.h:57
Definition: NptList.h:54
Definition: PltSyncMediaBrowser.h:90