Class: Wiretap::ServerList

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

Instance Method Summary collapse

Constructor Details

#initializeObject

Server list doesn’t require any params for initialization



100
101
102
# File 'ext/serverlist.cpp', line 100

static VALUE wiretap_server_list_initialize(VALUE self) {
	return self;
}

Instance Method Details

#[](index) ⇒ Object

Get server by it’s index



135
136
137
138
139
140
141
142
# File 'ext/serverlist.cpp', line 135

static VALUE wiretap_server_list_get_at(VALUE self, VALUE index) {
	WireTapServerList* server_list;
	Data_Get_Struct(self, WireTapServerList, server_list);

	WireTapServerList::ServerInfo node;
	RUN_E(server_list->getNode(FIX2INT(index), node), server_list);
  return wiretap_server_info_create(node);; 
}

#countObject

Number of available servers



120
121
122
123
124
125
126
127
128
129
130
# File 'ext/serverlist.cpp', line 120

static VALUE wiretap_server_list_count(VALUE self) {
	WireTapServerList* server_list;
	Data_Get_Struct(self, WireTapServerList, server_list);

	int num = 0;
	//RUN_E(server_list->getNumNodes(num), server_list);
	if(!server_list->getNumNodes(num)) {
		rb_warn("Problem in wiretap: %s. File: %s: %d", server_list->lastError(), __FILE__, __LINE__);
	}
	return INT2FIX(num);
}

#eachObject

Eval block on each server



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'ext/serverlist.cpp', line 147

static VALUE wiretap_server_list_each(VALUE self) {
	WireTapServerList* server_list;
	Data_Get_Struct(self, WireTapServerList, server_list);

	int num;
	
	RUN_E(server_list->getNumNodes(num), server_list);

	for(int i = 0; i < num; i++) {
		WireTapServerList::ServerInfo node;
		RUN_E(server_list->getNode(i, node), server_list);
	  rb_yield(wiretap_server_info_create(node));
	}
	return self;
}

#lengthObject

Number of available servers



120
121
122
123
124
125
126
127
128
129
130
# File 'ext/serverlist.cpp', line 120

static VALUE wiretap_server_list_count(VALUE self) {
	WireTapServerList* server_list;
	Data_Get_Struct(self, WireTapServerList, server_list);

	int num = 0;
	//RUN_E(server_list->getNumNodes(num), server_list);
	if(!server_list->getNumNodes(num)) {
		rb_warn("Problem in wiretap: %s. File: %s: %d", server_list->lastError(), __FILE__, __LINE__);
	}
	return INT2FIX(num);
}

#resolve(storage) ⇒ Object

resolve server by it’s storage ID



107
108
109
110
111
112
113
114
115
# File 'ext/serverlist.cpp', line 107

static VALUE wiretap_server_list_resolve(VALUE self, VALUE storage) {
	WireTapServerList* server_list;
	Data_Get_Struct(self, WireTapServerList, server_list);

	WireTapServerId host;
	RUN_E(server_list->resolveStorageId(CSTR(storage), host), server_list);
	return Qnil;
	//return wiretap_to_str(host);
}