forked from Softmotions/ejdb-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathejdb_cmd.h
More file actions
98 lines (70 loc) · 2.71 KB
/
ejdb_cmd.h
File metadata and controls
98 lines (70 loc) · 2.71 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
/**************************************************************************************************
* EJDB database library http://ejdb.org
* Copyright (C) 2012-2013 Softmotions Ltd <info@softmotions.com>
*
* This file is part of EJDB.
* EJDB is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License or any later version. EJDB is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* You should have received a copy of the GNU Lesser General Public License along with EJDB;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA.
*************************************************************************************************/
#ifndef EJDB_CMD_H
#define EJDB_CMD_H
#include <uv.h>
#include <v8.h>
#include <string>
namespace ejdb {
template < typename T, typename D = void > class EIOCmdTask {
public:
//uv request
uv_work_t uv_work;
v8::Persistent<v8::Function> cb;
T* wrapped;
//cmd spec
int cmd;
D* cmd_data;
//cmd return data
int cmd_ret;
int cmd_ret_data_length;
std::string cmd_ret_msg;
//entity type
int entity;
//Pointer to free_cmd_data function
void (*free_cmd_data)(EIOCmdTask<T, D>*);
public:
static void free_val(EIOCmdTask<T, D>* dtask) {
if (dtask->cmd_data) {
free(dtask->cmd_data);
dtask->cmd_data = NULL;
}
}
static void delete_val(EIOCmdTask<T, D>* dtask) {
if (dtask->cmd_data) {
delete dtask->cmd_data;
dtask->cmd_data = NULL;
}
}
public:
EIOCmdTask(const v8::Handle<v8::Function>& _cb, T* _wrapped, int _cmd,
D* _cmd_data, void (*_free_cmd_data)(EIOCmdTask<T, D>*)) :
wrapped(_wrapped), cmd(_cmd), cmd_data(_cmd_data), cmd_ret(0), cmd_ret_data_length(0), entity(0) {
this->free_cmd_data = _free_cmd_data;
this->cb = v8::Persistent<v8::Function>::New(_cb);
this->wrapped->Ref();
this->uv_work.data = this;
}
virtual ~EIOCmdTask() {
this->cb.Dispose();
this->wrapped->Unref();
if (this->free_cmd_data) {
this->free_cmd_data(this);
}
}
};
}
#endif /* EJDB_CMD_H */