Browse files

wait for logout before release... keep on segfaulting though

  • Loading branch information...
1 parent b3a7223 commit 56eea54c95409e7c122fc61b97d4b1bcb599df40 @Floby committed Dec 21, 2012
Showing with 41 additions and 6 deletions.
  1. +10 −1 lib/Session.js
  2. +29 −1 src/session.cc
  3. +2 −4 test/test-010-session02-login.js
View
11 lib/Session.js
@@ -61,9 +61,12 @@ Session.prototype._setupNativeCallbacks = function _setupNativeCallbacks() {
var self = this;
this._sp_session.logged_in = function(err) {
console.log('JS LOGIN CALLBACK!!!');
- console.log(self)
self.emit('login', err);
}
+ this._sp_session.logged_out = function() {
+ console.log('JS LOGOUT CALLBACK')
+ self.emit('logout');
+ }
};
Session.prototype._startProcessingEvents = function _startProcessingEvents() {
@@ -101,5 +104,11 @@ Session.prototype.login = function login(login, password) {
if('string' != typeof password) throw new TypeError('password should be a string')
b.session_login(this._sp_session, login, password);
};
+Session.prototype.logout = function logout(cb) {
+ b.session_logout(this._sp_session);
+ if(typeof cb === 'function') {
+ this.on('logout', cb)
+ }
+};
module.exports = Session;
View
30 src/session.cc
@@ -48,6 +48,21 @@ static void call_logged_in_callback(sp_session* session, sp_error error) {
return;
}
static void call_logged_out_callback(sp_session* session) {
+ ObjectHandle<sp_session>* s = (ObjectHandle<sp_session>*) sp_session_userdata(session);
+ Handle<Object> o = s->object;
+ Handle<Value> cbv = o->Get(String::New("logged_out"));
+ if(!cbv->IsFunction()) {
+ fprintf(stderr, "NOT A FUNCTION\n");
+ return;
+ }
+
+ Handle<Function> cb = Local<Function>(Function::Cast(*cbv));
+ const unsigned int argc = 0;
+ Local<Value> argv[argc] = {};
+ cb->Call(Context::GetCurrent()->Global(), argc, argv);
+ fprintf(stderr, "KIKOO LOGOUT\n");
+
+ return;
}
static void call_metadata_updated_callback(sp_session* session) {
}
@@ -195,7 +210,6 @@ static Handle<Value> Session_Create(const Arguments& args) {
//sp_error error = sp_session_create(session_config->pointer, &session->pointer);
sp_error error = sp_session_create(&spconfig, &(session->pointer));
NSP_THROW_IF_ERROR(error);
-
fprintf(stderr, "CREATED SESSION at %x IN HANDLE %x (%x)\n", session->pointer, session, &session->pointer);
return scope.Close(session->object);
@@ -240,6 +254,19 @@ static Handle<Value> Session_Login(const Arguments& args) {
return scope.Close(Undefined());
}
+static Handle<Value> Session_Logout(const Arguments& args) {
+ HandleScope scope;
+
+ assert(args.Length() == 1);
+ assert(args[0]->IsObject());
+
+ ObjectHandle<sp_session>* session = ObjectHandle<sp_session>::Unwrap(args[0]);
+ sp_error error = sp_session_logout(session->pointer);
+ NSP_THROW_IF_ERROR(error);
+
+ return scope.Close(Undefined());
+}
+
static Handle<Value> Session_Process_Events(const Arguments& args) {
HandleScope scope;
@@ -260,5 +287,6 @@ void nsp::init_session(Handle<Object> target) {
NODE_SET_METHOD(target, "session_create", Session_Create);
NODE_SET_METHOD(target, "session_release", Session_Release);
NODE_SET_METHOD(target, "session_login", Session_Login);
+ NODE_SET_METHOD(target, "session_logout", Session_Logout);
NODE_SET_METHOD(target, "session_process_events", Session_Process_Events);
}
View
6 test/test-010-session02-login.js
@@ -21,11 +21,9 @@ exports.testLoginIsSucessful = function(test) {
session.on('login', function(err) {
console.log('ON TEST LOGIN CALLBACK');
test.equal(err, null, 'There should be no error');
- setTimeout(function() {
- console.log('closing the session')
+ session.logout(function() {
session.close();
- console.log('session closed');
test.done();
- }, 10);
+ });
});
}

0 comments on commit 56eea54

Please sign in to comment.