forked from hooklift/node-libvirt
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a connect() method using libuv worker to do it asynchronously
- Loading branch information
Showing
5 changed files
with
158 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "baton.h" | ||
|
||
namespace NodeLibvirt { | ||
|
||
Baton::Baton(Hypervisor *hypervisor, Persistent<Function> callback) { | ||
this->hypervisor_ = hypervisor; | ||
this->callback_ = callback; | ||
this->request_.data = this; | ||
this->error_ = NULL; | ||
} | ||
|
||
Persistent<Function> Baton::getCallback() { | ||
return this->callback_; | ||
} | ||
|
||
Hypervisor* Baton::getHypervisor() { | ||
return this->hypervisor_; | ||
} | ||
|
||
uv_work_t* Baton::getHandle() { | ||
return &this->request_; | ||
} | ||
|
||
void Baton::setError(virErrorPtr error) { | ||
this->error_ = error; | ||
} | ||
|
||
virErrorPtr Baton::getError() { | ||
return this->error_; | ||
} | ||
|
||
bool Baton::hasError() { | ||
return this->error_ != NULL; | ||
} | ||
|
||
ConnectBaton::ConnectBaton(Hypervisor *hypervisor, Persistent<Function> callback) | ||
: Baton(hypervisor, callback) { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef SRC_BATON_H_ | ||
#define SRC_BATON_H_ | ||
|
||
#include <node.h> | ||
#include <libvirt/virterror.h> | ||
#include "hypervisor.h" | ||
|
||
namespace NodeLibvirt { | ||
class Baton { | ||
public: | ||
Baton(Hypervisor *hypervisor, Persistent<Function> callback); | ||
Persistent<Function> getCallback(); | ||
Hypervisor* getHypervisor(); | ||
uv_work_t* getHandle(); | ||
void setError(virErrorPtr error); | ||
virErrorPtr getError(); | ||
bool hasError(); | ||
|
||
private: | ||
uv_work_t request_; | ||
Persistent<Function> callback_; | ||
Hypervisor *hypervisor_; | ||
virErrorPtr error_; | ||
}; | ||
|
||
class ConnectBaton : public Baton { | ||
public: | ||
ConnectBaton(Hypervisor *hypervisor, Persistent<Function> callback); | ||
virConnectPtr conn_; | ||
}; | ||
} | ||
|
||
#endif // SRC_BATON_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters