File: PltMediaServerObject.mm

package info (click to toggle)
xbmc 2%3A13.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 128,344 kB
  • ctags: 124,885
  • sloc: cpp: 678,122; ansic: 337,697; xml: 67,848; makefile: 10,193; sh: 8,957; pascal: 8,049; objc: 4,283; python: 3,179; asm: 2,510; java: 2,051; perl: 1,408; yacc: 1,315; tcl: 1,048; cs: 757; lisp: 506; awk: 222; lex: 148; ruby: 126; sed: 109
file content (224 lines) | stat: -rw-r--r-- 9,327 bytes parent folder | download | duplicates (7)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//
//  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];
        [capsule release];
        
        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];
        [capsule release];
        
        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];
        [capsule release];
        
        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];
        [capsule release];
        
        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;
}

- (void)dealloc
{
    [objectId release];
    [filter release];
    [sort release];
    [super dealloc];
}

@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;
}

- (void)dealloc
{
    [search release];
    [super dealloc];
}

@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;
}

- (void)dealloc
{
    [super dealloc];
}

@end

/*----------------------------------------------------------------------
|   PLT_DeviceHostObject
+---------------------------------------------------------------------*/
@interface PLT_DeviceHostObject (priv)
- (PLT_DeviceHostReference&)getDevice;
@end

/*----------------------------------------------------------------------
|   PLT_MediaServerObject
+---------------------------------------------------------------------*/
@implementation PLT_MediaServerObject

@synthesize delegate;

- (id)init 
{
    PLT_MediaConnect* server = new PLT_MediaConnect("Test");
    PLT_DeviceHostReference _device(server);
    if ((self = [super initWithDeviceHost:&_device])) {
        server->SetDelegate(new PLT_MediaServerDelegate_Wrapper(self));
    }
    return self;
}

- (void)dealloc
{
    PLT_DeviceHostReference& host = [self getDevice];
    delete ((PLT_MediaServer*)host.AsPointer())->GetDelegate();
    [super dealloc];
}

@end