-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathartistbrowse.cc
More file actions
102 lines (78 loc) · 3.37 KB
/
artistbrowse.cc
File metadata and controls
102 lines (78 loc) · 3.37 KB
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
/*
* =====================================================================================
*
* Filename: artistbrowse.cc
*
* Description: bindings for the artist subsystem
*
* Version: 1.0
* Revision: none
* Compiler: gcc
*
* Author: Linus Unnebäck, linus@folkdatorn.se
* Company: LinusU AB
*
* =====================================================================================
*/
#include "common.h"
using namespace v8;
using namespace nsp;
void cb_artistbrowse_complete (sp_artistbrowse *result, void *userdata) {
Persistent<Function> callback = static_cast<Function*>(userdata);
callback->Call(callback, 0, NULL);
callback.Dispose();
}
static Handle<Value> ArtistBrowse_Create(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 3);
assert(args[0]->IsObject()); // sp_session
assert(args[1]->IsObject()); // sp_artist
assert(args[2]->IsFunction()); // callback
ObjectHandle<sp_session> *session = ObjectHandle<sp_session>::Unwrap(args[0]);
ObjectHandle<sp_artist> *artist = ObjectHandle<sp_artist>::Unwrap(args[1]);
Handle<Function> callback = Persistent<Function>::New(Handle<Function>::Cast(args[2]));
ObjectHandle<sp_artistbrowse>* artistbrowse = new ObjectHandle<sp_artistbrowse>("sp_artistbrowse");
artistbrowse->pointer = sp_artistbrowse_create(session->pointer, artist->pointer, SP_ARTISTBROWSE_NO_TRACKS, cb_artistbrowse_complete, *callback);
return scope.Close(artistbrowse->object);
}
static Handle<Value> ArtistBrowse_Num_Albums(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject()); // sp_artistbrowse
ObjectHandle<sp_artistbrowse> *artistbrowse = ObjectHandle<sp_artistbrowse>::Unwrap(args[0]);
const int num = sp_artistbrowse_num_albums(artistbrowse->pointer);
return scope.Close(Number::New(num));
}
static Handle<Value> ArtistBrowse_Album(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 2);
assert(args[0]->IsObject()); // sp_artistbrowse
assert(args[1]->IsNumber()); // index
// input
ObjectHandle<sp_artistbrowse> *artistbrowse = ObjectHandle<sp_artistbrowse>::Unwrap(args[0]);
int index = args[1]->ToNumber()->Int32Value();
// output
sp_album* spalbum = sp_artistbrowse_album(artistbrowse->pointer, index);
ObjectHandle<sp_album>* album = new ObjectHandle<sp_album>("sp_album");
album->pointer = spalbum;
return scope.Close(album->object);
}
static Handle<Value> ArtistBrowse_Release(const Arguments& args) {
HandleScope scope;
// test arguments sanity
assert(args.Length() == 1);
assert(args[0]->IsObject()); // sp_artistbrowse
ObjectHandle<sp_artistbrowse> *artistbrowse = ObjectHandle<sp_artistbrowse>::Unwrap(args[0]);
sp_error error = sp_artistbrowse_release(artistbrowse->pointer);
NSP_THROW_IF_ERROR(error);
return scope.Close(Undefined());
}
void nsp::init_artistbrowse(Handle<Object> target) {
NODE_SET_METHOD(target, "artistbrowse_create", ArtistBrowse_Create);
NODE_SET_METHOD(target, "artistbrowse_num_albums", ArtistBrowse_Num_Albums);
NODE_SET_METHOD(target, "artistbrowse_album", ArtistBrowse_Album);
NODE_SET_METHOD(target, "artistbrowse_release", ArtistBrowse_Release);
}