Skip to content

Commit

Permalink
feat(worker): Added LookupInstanceByValueWorker class
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Mar 31, 2015
1 parent 910ba3c commit fc1b615
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/node_libvirt.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using namespace v8;
using namespace node;

#include "libvirt_handle.h"

#define NODE_LIBVIRT_VERSION "v0.1.0"
#define LIBVIRT_THROW_EXCEPTION(err) \
v8::Local<v8::Value> exception = v8::Exception::Error( \
Expand Down
8 changes: 4 additions & 4 deletions src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace NodeLibvirt {

LibVirtWorker::LibVirtWorker(NanCallback *callback, virConnectPtr conn)
: NanAsyncWorker(callback), conn_(conn), virerror_(NULL)
LibVirtWorker::LibVirtWorker(NanCallback *callback, const LibVirtHandle &handle)
: NanAsyncWorker(callback), handle_(handle), virerror_(NULL)
{
}

LibVirtWorker::~LibVirtWorker()
{
}

virConnectPtr LibVirtWorker::Connection() const
LibVirtHandle LibVirtWorker::Handle() const
{
return conn_;
return handle_;
}

void LibVirtWorker::SetVirError(virErrorPtr error)
Expand Down
45 changes: 35 additions & 10 deletions src/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>

namespace NodeLibvirt {
#include "libvirt_handle.h"

typedef int (*GetNumOfType)(virConnectPtr);
typedef int (*GetListOfType)(virConnectPtr, char**, int);
namespace NodeLibvirt {

class Hypervisor;
class LibVirtWorker : public NanAsyncWorker
{
public:
explicit LibVirtWorker(NanCallback *callback, virConnectPtr connection);
explicit LibVirtWorker(NanCallback *callback, const LibVirtHandle &handle);
~LibVirtWorker();

virConnectPtr Connection() const;
LibVirtHandle Handle() const;

virErrorPtr VirError() const;
void SetVirError(virErrorPtr error);
Expand All @@ -29,7 +28,7 @@ class LibVirtWorker : public NanAsyncWorker
virtual void HandleErrorCallback();

private:
virConnectPtr conn_;
LibVirtHandle handle_;
virErrorPtr virerror_;

};
Expand All @@ -38,8 +37,8 @@ template <typename T>
class PrimitiveReturnWorker : public LibVirtWorker
{
public:
explicit PrimitiveReturnWorker(NanCallback *callback, virConnectPtr connection)
: LibVirtWorker(callback, connection) {}
explicit PrimitiveReturnWorker(NanCallback *callback, const LibVirtHandle &handle)
: LibVirtWorker(callback, handle) {}

protected:
void HandleOKCallback() {
Expand All @@ -60,8 +59,8 @@ template <typename T1, typename T2>
class ListReturnWorker : public LibVirtWorker
{
public:
explicit ListReturnWorker(NanCallback *callback, virConnectPtr connection)
: LibVirtWorker(callback, connection) {}
explicit ListReturnWorker(NanCallback *callback, const LibVirtHandle &handle)
: LibVirtWorker(callback, handle) {}

protected:
virtual void HandleOKCallback() {
Expand All @@ -82,6 +81,32 @@ class ListReturnWorker : public LibVirtWorker
std::vector<T1> data_;
};

template <typename T>
class LookupInstanceByValueWorker : public LibVirtWorker
{
public:
explicit LookupInstanceByValueWorker(NanCallback *callback,
const LibVirtHandle &handle,
const std::string &value)
: LibVirtWorker(callback, handle), value_(value) {}

protected:
virtual void HandleOKCallback() {
NanScope();
v8::Local<v8::Value> argv[] = {
NanNull(),
T::NewInstance(lookupHandle_)
};

callback->Call(2, argv);
}

std::string value_;
LibVirtHandle lookupHandle_;

};


} // namespace NodeLibvirt

#endif // SRC_WORKER_H_

0 comments on commit fc1b615

Please sign in to comment.