1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
//
// PltMediaServerObject.mm
// Platinum
//
// Created by Sylvain on 9/14/10.
// Copyright 2010 Plutinosoft LLC. All rights reserved.
//
#import "Platinum.h"
#import "PltMediaServerObject.h"
#import "PltMediaConnect.h"
/*----------------------------------------------------------------------
| PLT_MediaServerDelegate_Wrapper
+---------------------------------------------------------------------*/
class PLT_MediaServerDelegate_Wrapper : public PLT_MediaServerDelegate {
public:
PLT_MediaServerDelegate_Wrapper(PLT_MediaServerObject* target) : m_Target(target) {}
NPT_Result OnBrowseMetadata(PLT_ActionReference& action,
const char* object_id,
const char* filter,
NPT_UInt32 starting_index,
NPT_UInt32 requested_count,
const char* sort_criteria,
const PLT_HttpRequestContext& context) {
if (![m_Target.delegate respondsToSelector:@selector(onBrowseMetadata:)])
return NPT_FAILURE;
PLT_MediaServerBrowseCapsule* capsule =
[[PLT_MediaServerBrowseCapsule alloc] initWithAction:action.AsPointer()
objectId:object_id
filter:filter
start:starting_index
count:requested_count
sort:sort_criteria
context:(PLT_HttpRequestContext*)&context];
NPT_Result result = [m_Target.delegate onBrowseMetadata:capsule];
return result;
}
NPT_Result OnBrowseDirectChildren(PLT_ActionReference& action,
const char* object_id,
const char* filter,
NPT_UInt32 starting_index,
NPT_UInt32 requested_count,
const char* sort_criteria,
const PLT_HttpRequestContext& context) {
if (![m_Target.delegate respondsToSelector:@selector(onBrowseDirectChildren:)])
return NPT_FAILURE;
PLT_MediaServerBrowseCapsule* capsule =
[[PLT_MediaServerBrowseCapsule alloc] initWithAction:action.AsPointer()
objectId:object_id
filter:filter
start:starting_index
count:requested_count
sort:sort_criteria
context:(PLT_HttpRequestContext*)&context];
NPT_Result result = [m_Target.delegate onBrowseDirectChildren:capsule];
return result;
}
NPT_Result OnSearchContainer(PLT_ActionReference& action,
const char* container_id,
const char* search_criteria,
const char* filter,
NPT_UInt32 starting_index,
NPT_UInt32 requested_count,
const char* sort_criteria,
const PLT_HttpRequestContext& context) {
if (![m_Target.delegate respondsToSelector:@selector(onSearchContainer:)])
return NPT_FAILURE;
PLT_MediaServerSearchCapsule* capsule =
[[PLT_MediaServerSearchCapsule alloc] initWithAction:action.AsPointer()
objectId:container_id
search:search_criteria
filter:filter
start:starting_index
count:requested_count
sort:sort_criteria
context:(PLT_HttpRequestContext*)&context];
NPT_Result result = [m_Target.delegate onSearchContainer:capsule];
return result;
}
NPT_Result ProcessFileRequest(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response) {
PLT_HttpRequestContext _context(request, context);
PLT_MediaServerFileRequestCapsule* capsule =
[[PLT_MediaServerFileRequestCapsule alloc] initWithResponse:&response
context:&_context];
NPT_Result result = [m_Target.delegate onFileRequest:capsule];
return result;
}
private:
PLT_MediaServerObject* m_Target;
};
/*----------------------------------------------------------------------
| PLT_MediaServerBrowseCapsule
+---------------------------------------------------------------------*/
@implementation PLT_MediaServerBrowseCapsule
@synthesize objectId, filter, start, count, sort;
- (id)initWithAction:(PLT_Action*)action objectId:(const char*)_id filter:(const char*)_filter start:(NPT_UInt32)_start count:(NPT_UInt32)_count sort:(const char*)_sort context:(PLT_HttpRequestContext*)_context
{
if ((self = [super initWithAction:action])) {
objectId = [[NSString alloc] initWithCString:_id encoding:NSUTF8StringEncoding];
filter = [[NSString alloc] initWithCString:(_filter==NULL)?"":_filter
encoding:NSUTF8StringEncoding];
sort = [[NSString alloc] initWithCString:(_sort==NULL)?"":_sort
encoding:NSUTF8StringEncoding];
start = _start;
count = _count;
context = _context;
}
return self;
}
@end
/*----------------------------------------------------------------------
| PLT_MediaServerSearchCapsule
+---------------------------------------------------------------------*/
@implementation PLT_MediaServerSearchCapsule
@synthesize search;
- (id)initWithAction:(PLT_Action*)action objectId:(const char*)_id search:(const char*)_search filter:(const char*)_filter start:(NPT_UInt32)_start count:(NPT_UInt32)_count sort:(const char*)_sort context:(PLT_HttpRequestContext*)_context
{
if ((self = [super initWithAction:action
objectId:_id
filter:_filter
start:_start
count:_count
sort:_sort
context:_context])) {
search = [[NSString alloc] initWithCString:_search encoding:NSUTF8StringEncoding];
}
return self;
}
@end
/*----------------------------------------------------------------------
| PLT_MediaServerFileRequestCapsule
+---------------------------------------------------------------------*/
@implementation PLT_MediaServerFileRequestCapsule
- (id)initWithResponse:(NPT_HttpResponse*)_response context:(PLT_HttpRequestContext*)_context
{
if ((self = [super init])) {
response = _response;
context = _context;
}
return self;
}
@end
/*----------------------------------------------------------------------
| PLT_MediaServerObject
+---------------------------------------------------------------------*/
@interface PLT_MediaServerObject () {
PLT_MediaServerDelegate_Wrapper *_wrapper;
}
@end
@implementation PLT_MediaServerObject
- (id)init
{
if ((self = [super init])) {
PLT_MediaConnect* server = new PLT_MediaConnect("Test");
PLT_DeviceHostReference _device(server);
[self setDevice:&_device];
_wrapper = new PLT_MediaServerDelegate_Wrapper(self);
server->SetDelegate(_wrapper);
}
return self;
}
- (void)dealloc
{
delete _wrapper;
}
@end
|