Class: Wiretap::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/wiretap.rb,
ext/server.cpp

Instance Method Summary collapse

Constructor Details

#initialize(hostname) ⇒ Object

Use Server.new(hostname) to connect to specified server. This method opens server by it’s hostname. Not by id.



43
44
45
46
47
48
49
# File 'ext/server.cpp', line 43

static VALUE wiretap_server_connect(VALUE self, VALUE hostname) {
	Check_Type(hostname, T_STRING);
	Check_Type(self, T_DATA);

	DATA_PTR(self) = new WireTapServerHandle(CSTR(hostname));
	return self;
}

Instance Method Details

#alive?Boolean

Check, whether connection to server is still alive

Returns:

  • (Boolean)


150
151
152
153
154
155
156
157
# File 'ext/server.cpp', line 150

def alive?
  begin
    Timeout.timeout(1) {TCPSocket.new(hostname,'7549')}
    real_alive?
  rescue Timeout::Error, SocketError, Errno::ECONNREFUSED
    false
  end
end

#childrenObject



32
33
34
# File 'lib/wiretap.rb', line 32

def children
  root.children
end

#close!Object

If destruction of server interface is required, call close on it to be sure, that server has been closed right now.



25
26
27
28
29
30
31
32
33
# File 'ext/server.cpp', line 25

static VALUE wiretap_server_close(VALUE self) {
	rb_funcall(self, rb_intern("stop!"), 0);

	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	delete server;
	DATA_PTR(self) = 0;
	return Qtrue;
}

#find(path) ⇒ Object Also known as: []



13
14
15
# File 'lib/wiretap.rb', line 13

def find(path)
  root.find(path.split("/"))
end

#hostnameObject

Get hostname of server, to which connection is established.



54
55
56
57
58
# File 'ext/server.cpp', line 54

static VALUE wiretap_server_hostname(VALUE self) {
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	return rb_str_new2(server->getHostName());
}

#last_errorObject

Get message, explaining last error, occured on server



176
177
178
179
180
# File 'ext/server.cpp', line 176

static VALUE wiretap_server_last_error(VALUE self) {
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	return rb_str_new2(server->lastError());
}

#open(id) ⇒ Object

Open node by id



77
78
79
80
81
82
83
84
85
# File 'ext/server.cpp', line 77

static VALUE wiretap_server_open_node(VALUE self, VALUE id) {
	Check_Type(id, T_STRING);

	WireTapServerHandle* server;
	Safe_Get_Server(self, server);

	WireTapNodeHandle node(*server, CSTR(id));
	return wiretap_node_create_with(node, self, Qnil);
}

#productObject

Get product name of the server



102
103
104
105
106
107
108
# File 'ext/server.cpp', line 102

static VALUE wiretap_server_product(VALUE self) {
	WireTapStr str;
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	RUN_E(server->getProduct(str), server);
	return wiretap_to_str(str);
}

#protocolObject

Get version of server protocol. major.minor



137
138
139
140
141
142
143
144
145
# File 'ext/server.cpp', line 137

static VALUE wiretap_server_protocol(VALUE self) {
	int major, minor;
	char buf[256];
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	RUN_E(server->getProtocolVersion(major, minor), server);
	snprintf(buf, sizeof(buf), "%d.%d", major, minor);
	return rb_str_new2(buf);
}

#real_alive?Object



22
# File 'lib/wiretap.rb', line 22

alias :real_alive? :alive?

#rootObject

Get root node of server



64
65
66
67
68
69
70
71
72
# File 'ext/server.cpp', line 64

static VALUE wiretap_server_root(VALUE self) {
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);

	WireTapNodeHandle root_node;
	SERVERRUN_E(server, server->getRootNode(root_node));

	return wiretap_node_create_with(root_node, self, Qnil);
}

#stop!Object

Theoretically, it is possible to stop continious operation on server from other thread. Practically, it is impossible unless ruby gets threads



164
165
166
167
168
169
170
171
# File 'ext/server.cpp', line 164

static VALUE wiretap_server_stop(VALUE self) {
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	if(server->ping()) {
		server->stop();
	}
	return self;
}

#storageObject

Get ID of server storage



126
127
128
129
130
131
132
# File 'ext/server.cpp', line 126

static VALUE wiretap_server_storage(VALUE self) {
	WireTapStr str;
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	RUN_E(server->getStorageId(str), server);
	return wiretap_to_str(str);
}

#uriObject



18
19
20
# File 'lib/wiretap.rb', line 18

def uri
  hostname
end

#vendorObject

Get vendor of server



91
92
93
94
95
96
97
# File 'ext/server.cpp', line 91

static VALUE wiretap_server_vendor(VALUE self) {
	WireTapStr str;
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	RUN_E(server->getVendor(str), server);
	return wiretap_to_str(str);
}

#versionObject

Get version of server



113
114
115
116
117
118
119
120
121
# File 'ext/server.cpp', line 113

static VALUE wiretap_server_version(VALUE self) {
	int major, minor;
	char buf[256];
	WireTapServerHandle* server;
	Safe_Get_Server(self, server);
	RUN_E(server->getVersion(major, minor), server);
	snprintf(buf, sizeof(buf), "%d.%d", major, minor);
	return rb_str_new2(buf);
}