forked from ibmruntimes/vsam.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVsamFile.h
88 lines (76 loc) · 2.91 KB
/
VsamFile.h
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
/*
* Licensed Materials - Property of IBM
* (C) Copyright IBM Corp. 2017. All Rights Reserved.
* US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
#ifndef VSAM_H
#define VSAM_H
#include <node.h>
#include <node_object_wrap.h>
#include <uv.h>
#include <string>
class VsamFile : public node::ObjectWrap {
public:
static void Init(v8::Isolate* isolate);
static void OpenSync(const v8::FunctionCallbackInfo<v8::Value>& args);
static void AllocSync(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Exist(const v8::FunctionCallbackInfo<v8::Value>& args);
static v8::Persistent<v8::Function> OpenSyncConstructor;
static v8::Persistent<v8::Function> AllocSyncConstructor;
~VsamFile();
private:
struct LayoutItem {
enum DataType {
STRING
};
std::vector<char> name;
int maxLength;
DataType type;
LayoutItem(v8::String::Utf8Value& n, int m, DataType t) :
name(n.length()), maxLength(m), type(t) {
memcpy(&name[0], *n, n.length());
}
};
explicit VsamFile(std::string&, std::vector<LayoutItem>&,
v8::Isolate* isolate, bool alloc);
/* Entry point from Javascript */
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Read(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Find(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Update(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Write(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Delete(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Dealloc(const v8::FunctionCallbackInfo<v8::Value>& args);
/* Work functions */
static void Open(uv_work_t* req);
static void Alloc(uv_work_t* req);
static void Dealloc(uv_work_t* req);
static void Read(uv_work_t* req);
static void Find(uv_work_t* req);
static void Update(uv_work_t* req);
static void Write(uv_work_t* req);
static void Delete(uv_work_t* req);
/* Work callback functions */
v8::Persistent<v8::Function, v8::CopyablePersistentTraits<v8::Function>> cb_;
static void OpenCallback(uv_work_t* req, int statusj);
static void AllocCallback(uv_work_t* req, int statusj);
static void DeallocCallback(uv_work_t* req, int statusj);
static void ReadCallback(uv_work_t* req, int status);
static void UpdateCallback(uv_work_t* req, int status);
static void WriteCallback(uv_work_t* req, int status);
static void DeleteCallback(uv_work_t* req, int status);
/* Private methods */
static void SetPrototypeMethods(v8::Local<v8::FunctionTemplate>& tpl);
static void Construct(const v8::FunctionCallbackInfo<v8::Value>& args, bool alloc);
/* Data */
v8::Isolate* isolate_;
std::string path_;
std::string key_;
std::vector<LayoutItem> layout_;
unsigned keylen_, reclen_;
FILE *stream_;
void *buf_;
int lastrc_;
std::string errmsg_;
};
#endif