Welcome to mirror list, hosted at ThFree Co, Russian Federation.

verse_common.c « src « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1336151e3af2f64d0ec387633e03a15290c81c0f (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/**
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Contributor(s): Jiri Hnidek.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#ifdef WITH_VERSE

#include <string.h>
#include <stdlib.h>

#include "MEM_guardedalloc.h"

#include "mydevice.h"

#include "DNA_object_types.h"
#include "DNA_mesh_types.h"

#include "BKE_global.h"
#include "BKE_blender.h"

#include "BIF_verse.h"
#include "BIF_space.h"
#include "BIF_interface.h"

extern ListBase session_list;
extern ListBase server_list;

/*
 * this function creates popup menu with all active VerseSessions
 * it return pointer at selected VerseSession, if no VerseSession
 * is selected, then NULL is returned
 */
VerseSession *session_menu(void)
{
	struct VerseSession *session;
	char session_number[10];
	short i=1, num=1;
	char session_address_list[1024];	/* pupmenu business */

	session_number[0] = '\0';
	session_address_list[0] = '\0';

	strcat(session_address_list, "Session list %t");

	session = session_list.first;

	while(session){
		strcat(session_address_list, "| ");
		strcat(session_address_list, session->address);
		strcat(session_address_list, " %x");
		sprintf(session_number, "%d", num);
		strcat(session_address_list, session_number);
		num++;
		session = session->next;
	}

	printf("session list: %s\n", session_address_list);
	num = pupmenu(session_address_list);

	if(num==-1) return NULL;

	session = session_list.first;

	while(session) {
		if(i==num) return session;
		i++;
		session = session->next;
	}

	return NULL;
}

/*
 * returns name of verse client (it is used as avatar's name)
 */
char *verse_client_name(void)
{
	char *client_name;
	char blender_version[5];
	short name_lenght = 14;

#ifndef WIN32
	char *hostname;
	hostname = getenv("HOSTNAME");
	if(hostname) name_lenght += strlen(hostname);
#endif

	client_name = (char*)MEM_mallocN(sizeof(char)*name_lenght, "verse client name");
	client_name[0] = '\0';

	strcat(client_name, "blender_");
	blender_version[0] = '\0';
	sprintf(blender_version, "%d", BLENDER_VERSION);
	strcat(client_name, blender_version);

#ifndef WIN32
	/* add at the end of the client name hostname */
	if(hostname) {
		strcat(client_name, ":");
		strcat(client_name, hostname);
	}
#endif

	return client_name;
}

/*===========================================================
 *
 *   functions executed after calling callback functions
 *
 ============================================================*/

/*
 * this function is called, when some tag was changed or new tag was created
 */
void post_tag_change(VTag *vtag)
{
	printf("\tnew tag %s was created or changed\n", vtag->name);
}

/*
 * this function is called, when verse taggroup was created
 */
void post_taggroup_create(VTagGroup *vtaggroup)
{
	printf("\tnew taggroup %s was created\n", vtaggroup->name);
}

/*
 * this function is called after creating of new VerseNode
 */
void post_node_create(VNode *vnode)
{
	struct VerseSession *session = vnode->session;

	if((session->flag & VERSE_AUTOSUBSCRIBE) && (vnode->owner_id != VN_OWNER_MINE)) {
		if(vnode->type == V_NT_OBJECT) {
			create_object_from_verse_node(vnode);
		}
		else if(vnode->type == V_NT_GEOMETRY) {
			create_mesh_from_geom_node(vnode);;
		}
	}

	allqueue(REDRAWOOPS, 0);
}

/*
 * this function is called after destroying of VerseNode
 */
void post_node_destroy(VNode *vnode)
{
	allqueue(REDRAWOOPS, 0);

	/* TODO: destroy bindings between vnode and blender data structures */
}

/*
 * this function is calles after renaming of VerseNode by verse_server
 */
void post_node_name_set(VNode *vnode)
{
	/* if VerseNode has coresponding blender data structure, then
	 * change ID name of data structure */
	if(vnode->type==V_NT_OBJECT) {
		struct Object *ob;
		ob = (Object*)((VObjectData*)vnode->data)->object;
		if(ob) {
			char *str;
			str = (char*)malloc(sizeof(char)*(strlen(vnode->name)+3));
			str[0] = '\0';
			strcat(str, "OB");
			strcat(str, vnode->name);
			strncpy(ob->id.name, str, 23);
			printf("\tob->id.name: %s\n", ob->id.name);
			free(str);
		}
	}
	else if(vnode->type==V_NT_GEOMETRY) {
		struct Mesh *me;

		me = (Mesh*)((VGeomData*)vnode->data)->mesh;
		if(me) {
			char *str;
			str = (char*)malloc(sizeof(char)*(strlen(vnode->name)+3));
			str[0] = '\0';
			strcat(str, "ME");
			strcat(str, vnode->name);
			strncpy(me->id.name, str, 23);
			printf("\tme->id.name: %s\n", me->id.name);
			free(str);
		}
	}

	allqueue(REDRAWALL, 0);
}

/*
 * this function is called after acception connection with verse server
 */
void post_connect_accept(VerseSession *session)
{
	VerseServer *server;
	
	G.f |= G_VERSE_CONNECTED;

	session->counter = 0;

	server = server_list.first;
	while(server) {
		if(strcmp(server->ip, session->address)==0) {
			server->flag = session->flag;
			break;
		}
		server = server->next;
	}

	allqueue(REDRAWOOPS, 0);
}

void post_server_add(void)
{
	allqueue(REDRAWOOPS, 0);
}

/*
 * this function is called, when connestion with verse server is ended/terminated/etc.
 */
void post_connect_terminated(VerseSession *session)
{
	VerseServer *server;
	server = server_list.first;
	while(server) {
		if(strcmp(server->ip, session->address)==0) {
			server->flag = 0;
			server->session=NULL;
			break;
		}
		server = server->next;
	}

	/* if it is last session, then no other will exist ... set Global flag */
	if((session->prev==NULL) && (session->next==NULL))
		G.f &= ~G_VERSE_CONNECTED;

	allqueue(REDRAWOOPS, 0);
}

/*
 * if connection wasn't accepted, then free VerseSession
 * and print warning message with popupmenu
 */
void post_connect_update(VerseSession *session)
{
	if(session->flag & VERSE_CONNECTING) {
		session->counter++;
		if(session->counter > MAX_UNCONNECTED_EVENTS) {
			char *str;
			/* popup menu*/
			str = malloc(sizeof(char)*(strlen(session->address)+35));
			str[0]='\0';
			strcat(str, "Error%t|No response from server: ");
			strcat(str, session->address);
			pupmenu(str);
			free(str);

			session->flag = 0;
			session->counter = 0;
			session->post_connect_terminated(session);
			free_verse_session(session);
		}
	}
}

#endif