00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <string.h>
00025 #include <zlib.h>
00026
00027 #include "Client.h"
00028 #include "Memory.h"
00029 #include "App.h"
00030 #include "Window.h"
00031 #include "NetCommon.h"
00032 #include "Common.h"
00033
00034 #include "debug.h"
00035 #include "xml_Gui.h"
00036
00037
00038 typedef struct client_Window_s
00039 {
00040 Window_t *window;
00041 char *name;
00042 int (*event_handler)(gui_App_t *app, Window_t *win, u32 gadget_id, int event, u32 event_data);
00043 gui_App_t *app;
00044 Node_t *node;
00045 List_t *timerlist;
00046 int timer_stop;
00047 u32 userdata;
00048 } client_Window_t;
00049
00050
00051 typedef struct client_File_s
00052 {
00053 u8 *data;
00054 u32 type;
00055 int size;
00056 int real_size;
00057 } client_File_t;
00058
00059
00060 typedef struct client_Timer_s
00061 {
00062 u32 timer;
00063 u32 millis;
00064 u32 flags;
00065 u32 userdata;
00066 client_Window_t *nwin;
00067 } client_Timer_t;
00068
00069
00070 static u32 client_CliSRq_CallGadgetTL(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, tag *taglist);
00071 static u32 client_CliARq_CallGadgetTL(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, tag *taglist);
00072 static void client_CliARq_CloseWindow(gui_App_t *app, Window_t *win);
00073 static Window_t *client_CliSRq_OpenWindowTL(gui_App_t *app, Rect_t *rect, char *window_name, int (*event_handler)(gui_App_t *,Window_t *,u32,int,u32), u32 flags, tag *taglist);
00074
00075
00076 static client_Window_t *client_FindWindow(List_t *winlist, Window_t *win)
00077 {
00078 client_Window_t *ret=NULL;
00079 Node_t *node;
00080
00081 debug_Begin();
00082
00083 for(node=list_GetNodeHead(winlist);node!=NULL;node=list_GetNodeNext(winlist,node))
00084 {
00085 ret=(client_Window_t *)list_GetNodeData(node);
00086 if(win==ret->window) break;
00087 ret=NULL;
00088 }
00089
00090 debug_End();
00091
00092 return(ret);
00093 }
00094
00095
00096 static char *client_LoadFile(char *name, int *len)
00097 {
00098 char *ret=NULL;
00099 size_t file_len;
00100 FILE *f;
00101
00102 debug_Begin();
00103
00104 debug_Message("load this: '%s'",name);
00105 if(name!=NULL&&NULL!=(f=fopen(name,"rb")))
00106 {
00107 if(0==(fseek(f,0L,SEEK_END)))
00108 {
00109 file_len=(size_t)ftell(f);
00110 if(0==(fseek(f,0L,SEEK_SET)))
00111 {
00112 if(NULL!=(ret=mem_malloc(file_len+1)))
00113 {
00114 ret[0]='\0';
00115 if(fread(ret,file_len,1,f)>0)
00116 {
00117 if(len!=NULL) *len=file_len+1;
00118 ret[file_len]='\0';
00119 debug_Message(" ...loaded");
00120 }
00121 else
00122 {
00123 mem_free(ret);
00124 ret=NULL;
00125 }
00126 }
00127 }
00128 }
00129 (void)fclose(f);
00130 }
00131 else debug_Warning("BAD file req name='%s'",name);
00132
00133 debug_End();
00134
00135 return(ret);
00136 }
00137
00138
00139 static u32 client_GetClientId(void)
00140 {
00141 static u32 curr_id=2;
00142 return(curr_id+=2);
00143 }
00144
00145
00146 static void client_ClientCleanup(gui_App_t *app)
00147 {
00148 debug_Begin();
00149
00150 if(app!=NULL&&0L!=app->conn)
00151 {
00152 net_ClearMsgList(app->conn);
00153 }
00154
00155 debug_End();
00156 }
00157
00158
00159
00160 static int client_ClientInit(gui_App_t *app, int *byteorder)
00161 {
00162 int ret=-1,rl,mlen;
00163 char *init, *initstr="?GUI L v1.1 ";
00164 char reply[]=".. . ..";
00165 struct glw_ConnUser *cuser;
00166
00167 debug_Begin();
00168
00169 if(app!=NULL&&NULL!=(cuser=(struct glw_ConnUser *)app->conn))
00170 {
00171 if(cuser->waitlist!=NULL) client_ClientCleanup(app);
00172 mlen=strlen(initstr)+strlen(app->name)+1;
00173 if(NULL!=(init=mem_malloc((size_t)mlen))&&NULL!=(cuser->waitlist=list_CreateList()))
00174 {
00175 strcpy(init,initstr);
00176 strcat(init,app->name);
00177 if(0<=(glw_Send(app->conn,(u8 *)init,mlen)))
00178 {
00179 rl=glw_Recv(app->conn,(u8 *)reply,7);
00180 debug_Message("reply: '%s'",reply);
00181 if(reply[3]=='L') *byteorder=0;
00182 else *byteorder=1;
00183 if(strncmp(reply,"OK",2)==0) ret=0;
00184 else debug_Error("Connection failed (code: %c%c)",reply[0],reply[1]);
00185 }
00186 mem_free(init);
00187 }
00188 }
00189
00190 debug_End();
00191
00192 return(ret);
00193 }
00194
00195
00196 void client_SendCloseApp(u32 conn, gui_App_t *app)
00197 {
00198 u32 m;
00199
00200 debug_Begin();
00201
00202 m=glw_htonl((u32)app);
00203 (void)glw_SendMsg(conn,REQ_CCLOSEAPP,client_GetClientId(),(u8 *)&m,4);
00204 glw_CloseApp(conn);
00205
00206 debug_End();
00207 }
00208
00209
00210 static int client_IsCompressableType(char *filename, u8 *file, int len)
00211 {
00212 int ret=0;
00213
00214 debug_Begin();
00215
00216 if(len>128)
00217 {
00218 if(strstr(filename,"xml")!=NULL&&strncmp("<?xml",(char *)file,5)==0) ret=1;
00219 else if(file[0]=='M'&&file[1]=='Z'&&file[2]==0x90) ret=1;
00220 }
00221
00222 debug_End();
00223
00224 return(ret);
00225 }
00226
00227
00228 static u8 *client_LoadAFile(char *filename, u32 *type, int *size, int *orig_len)
00229 {
00230 u8 *send_file=NULL,*file;
00231 int send_len,len=0;
00232
00233 debug_Begin();
00234
00235 if(orig_len!=NULL) *orig_len=0;
00236 if(size!=NULL) *size=0;
00237 if(type!=NULL) *type=FT_NORMAL;
00238 if(filename!=NULL&&NULL!=(file=(u8 *)client_LoadFile(filename,&len)))
00239 {
00240 if(orig_len!=NULL) *orig_len=len;
00241 send_file=file;
00242 send_len=len;
00243 if(client_IsCompressableType(filename,file,len)!=0)
00244 {
00245 send_len=(len*1.01)+12;
00246 if(NULL!=(send_file=mem_malloc(send_len)))
00247 {
00248 (void)compress(send_file,(u32 *)&send_len,file,(uLong)len);
00249 mem_free(file);
00250 if(type!=NULL) *type=FT_DEFLATED;
00251 }
00252 else send_len=len;
00253 }
00254 if(size!=NULL) *size=send_len;
00255 }
00256
00257 debug_End();
00258
00259 return(send_file);
00260 }
00261
00262
00263 static int client_LoadFiles(u32 conn, u8 **bd, u32 msgid)
00264 {
00265 int ret=-1,i;
00266 int filecnt,msg_size=0;
00267 char *name;
00268 client_File_t *files;
00269 u8 *msg,*m,*msg2;
00270
00271 debug_Begin();
00272
00273 if(bd!=NULL)
00274 {
00275 filecnt=net_MarshalGetLong(bd);
00276 if(NULL!=(files=mem_malloc(filecnt*sizeof(client_File_t))))
00277 {
00278 for(i=0;i<filecnt;i++)
00279 {
00280 name=net_MarshalGetString(bd);
00281 files[i].data=client_LoadAFile(name,&files[i].type,&files[i].size,&files[i].real_size);
00282 mem_free(name);
00283 msg_size+=files[i].size+12;
00284 }
00285 if(NULL!=(msg=mem_malloc(msg_size)))
00286 {
00287 m=msg;
00288 for(i=0;i<filecnt;i++)
00289 {
00290 m=net_MarshalPutLong(m,files[i].type);
00291 m=net_MarshalPutLong(m,files[i].real_size);
00292 m=net_MarshalPutBinary(m,files[i].data,files[i].size);
00293 }
00294 if(NULL!=(msg2=mem_malloc(msg_size+4)))
00295 {
00296 net_MarshalPutBinary(msg2,msg,msg_size);
00297 glw_SendMsg(conn,REQ_SLOADFILES|FL_REPLY,msgid,msg2,msg_size+4);
00298 mem_free(msg2);
00299 }
00300 mem_free(msg);
00301 }
00302 for(i=0;i<filecnt;i++) if(NULL!=files[i].data) mem_free(files[i].data);
00303 mem_free(files);
00304 }
00305 }
00306
00307 debug_End();
00308
00309 return(ret);
00310 }
00311
00312
00313 int client_CliProcessMessage(u32 conn, u32 userdata, struct glw_SockMsg *messg)
00314 {
00315 int ret=0,fromwait,stored=0;
00316 u8 *bd,*reply,*m;
00317 struct glw_ConnUser *cuser=(struct glw_ConnUser *)conn;
00318 gui_App_t *app=(gui_App_t *)userdata;
00319 struct glw_SockMsg *msg=NULL;
00320
00321 debug_Begin();
00322
00323 if(messg!=NULL)
00324 {
00325 fromwait=0;
00326 if(NULL!=(msg=mem_malloc(sizeof(struct glw_SockMsg))))
00327 {
00328 memcpy(msg,messg,sizeof(struct glw_SockMsg));
00329 }
00330 }
00331 else fromwait=1;
00332 do
00333 {
00334 if(fromwait!=0||msg==NULL) msg=net_MsgFromWaitList(conn);
00335 if(msg==NULL) break;
00336
00337 bd=msg->body;
00338 switch(msg->type)
00339 {
00340 case REQ_SAPP:
00341 {
00342 if(net_GetWaitfor(conn)==msg->type)
00343 {
00344 cuser->app=net_MarshalGetLong(&bd);
00345 ret=1;
00346 }
00347 break;
00348 }
00349 case REQ_SECHO:
00350 {
00351 glw_SendMsg(conn,msg->type|FL_REPLY,msg->id,NULL,0);
00352 break;
00353 }
00354 case REQ_SLOADFILES:
00355 {
00356 client_LoadFiles(conn,&bd,msg->id);
00357 break;
00358 }
00359 case REQ_SLOADFILE:
00360 {
00361 char *filename;
00362 u8 *send_file;
00363 u32 type;
00364 int send_len,msglen,ok=0,len;
00365 char empty[4+8];
00366
00367 filename=net_MarshalGetString(&bd);
00368 if(NULL!=(send_file=client_LoadAFile(filename,&type,&send_len,&len)))
00369 {
00370 msglen=send_len+4+8;
00371 if(NULL!=(reply=mem_malloc(msglen)))
00372 {
00373 m=reply;
00374 m=net_MarshalPutLong(m,type);
00375 m=net_MarshalPutLong(m,len);
00376 m=net_MarshalPutBinary(m,send_file,send_len);
00377 glw_SendMsg(conn,msg->type|FL_REPLY,msg->id,reply,msglen);
00378 mem_free(reply);
00379 ok=1;
00380 }
00381 mem_free(send_file);
00382 }
00383 if(ok==0)
00384 {
00385 m=empty;
00386 m=net_MarshalPutLong(m,FT_NORMAL);
00387 m=net_MarshalPutLong(m,0);
00388 m=net_MarshalPutBinary(m,NULL,0);
00389 glw_SendMsg(conn,msg->type|FL_REPLY,msg->id,empty,sizeof(empty));
00390 }
00391 mem_free(filename);
00392 break;
00393 }
00394 case REQ_SWINEVENT:
00395 {
00396 u32 rapp,gadget_id,event,event_data,ret;
00397 client_Window_t *nwin;
00398 Window_t *win;
00399 int msglen;
00400 u8 r[16];
00401
00402 if(cuser->waitfor==REQ_NONE)
00403 {
00404 rapp=net_MarshalGetLong(&bd);
00405 win=(Window_t *)net_MarshalGetLong(&bd);
00406 gadget_id=net_MarshalGetLong(&bd);
00407 event=net_MarshalGetLong(&bd);
00408 event_data=net_MarshalGetLong(&bd);
00409 nwin=client_FindWindow(app->windowlist,win);
00410 ret=(int)nwin->event_handler(app,(Window_t *)win,gadget_id,event,event_data);
00411
00412 m=r;
00413 if(ret==CLIENT_DISCARD_EVENT)
00414 {
00415
00416 msglen=16;
00417 m=net_MarshalPutLong(m,ret);
00418 m=net_MarshalPutLong(m,(u32)win);
00419 m=net_MarshalPutLong(m,gadget_id);
00420 m=net_MarshalPutLong(m,event);
00421 }
00422 else
00423 {
00424 msglen=4;
00425 m=net_MarshalPutLong(m,ret);
00426 }
00427 glw_SendMsg(conn,msg->type|FL_REPLY,msg->id,r,msglen);
00428 ret=0;
00429 }
00430 else
00431 {
00432
00433 stored=net_MsgToWaitList(conn,msg);
00434 }
00435 break;
00436 }
00437 case REQ_CECHO|FL_REPLY:
00438 {
00439 break;
00440 }
00441 case REQ_CCALLGAD|FL_REPLY:
00442 {
00443 if(cuser->waitfor!=REQ_NONE)
00444 {
00445 if(msg->id==cuser->userdata&&cuser->waitfor==msg->type)
00446 {
00447 cuser->userdata=net_MarshalGetLong(&bd);
00448 cuser->waitfor=REQ_NONE;
00449 ret=1;
00450 }
00451 else debug_Error("invalid message order - not implemented yet");
00452 }
00453 break;
00454 }
00455 case REQ_COPENWIN|FL_REPLY:
00456 {
00457
00458 if(msg->id==net_GetUserData(conn)&&net_GetWaitfor(conn)==msg->type)
00459 {
00460 cuser->userdata=net_MarshalGetLong(&bd);
00461 cuser->waitfor=REQ_NONE;
00462 ret=1;
00463 }
00464 else debug_Error("invalid message order - not implemented yet");
00465 break;
00466 }
00467 default:
00468 {
00469 debug_Error("Illegal message type: 0x%02x",(int)msg->type);
00470 }
00471 }
00472 if(stored==0)
00473 {
00474 mem_free(msg->body);
00475 mem_free(msg);
00476 }
00477 msg=NULL;
00478 }
00479 while(fromwait==0);
00480
00481 debug_End();
00482
00483 return(ret);
00484 }
00485
00486
00487
00488 static int client_TaglistMsgLen(tag *taglist)
00489 {
00490 int ret;
00491 tag *tags;
00492
00493 debug_Begin();
00494
00495 for(ret=4,tags=taglist;tags->Name!=TAG_DONE;tags=tag_GetNextTag(tags),ret+=4)
00496 {
00497 if((tags->Name&TAGT_STRING)!=0) ret+=net_StrMsgLen((char *)tags->Data);
00498 else ret+=4;
00499 }
00500
00501 debug_End();
00502
00503 return(ret);
00504 }
00505
00506
00507 u32 client_CallSGadget(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, u32 firsttag, ...)
00508 {
00509 return(client_CliSRq_CallGadgetTL(app,window,gadget_id,method,(tag *)&firsttag));
00510 }
00511 u32 client_CallSGadgetTL(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, tag *taglist)
00512 {
00513 return(client_CliSRq_CallGadgetTL(app,window,gadget_id,method,taglist));
00514 }
00515 u32 client_CallAGadget(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, u32 firsttag, ...)
00516 {
00517 return(client_CliARq_CallGadgetTL(app,window,gadget_id,method,(tag *)&firsttag));
00518 }
00519 u32 client_CallAGadgetTL(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, tag *taglist)
00520 {
00521 return(client_CliARq_CallGadgetTL(app,window,gadget_id,method,taglist));
00522 }
00523 void client_CloseWindow(gui_App_t *app, Window_t *win)
00524 {
00525 client_CliARq_CloseWindow(app,win);
00526 }
00527 Window_t *client_OpenWindow(gui_App_t *app, Rect_t *rect, char *window_name, int (*event_handler)(gui_App_t *,Window_t *,u32,int,u32), u32 flags, u32 firsttag, ...)
00528 {
00529 return(client_CliSRq_OpenWindowTL(app,rect,window_name,event_handler,flags,(tag *)&firsttag));
00530 }
00531 Window_t *client_OpenWindowTL(gui_App_t *app, Rect_t *rect, char *window_name, int (*event_handler)(gui_App_t *,Window_t *,u32,int,u32), u32 flags, tag *taglist)
00532 {
00533 return(client_CliSRq_OpenWindowTL(app,rect,window_name,event_handler,flags,taglist));
00534 }
00535
00536
00537
00538
00539
00540 static u32 client_CliSRq_CallGadgetTL(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, tag *taglist)
00541 {
00542 u32 ret,id;
00543
00544 debug_Begin();
00545
00546 id=client_CliARq_CallGadgetTL(app,window,gadget_id,method,taglist);
00547 net_SetState(app->conn,REQ_CCALLGAD|FL_REPLY,id);
00548 glw_MainLoopCli(app->conn,(u32)app);
00549 ret=net_GetUserData(app->conn);
00550
00551 debug_End();
00552
00553 return(ret);
00554 }
00555
00556
00557
00558
00559 static u32 client_CliARq_CallGadgetTL(gui_App_t *app, Window_t *window, u32 gadget_id, u32 method, tag *taglist)
00560 {
00561 u32 id=0L;
00562 int mlen;
00563 u8 *msg,*m;
00564
00565 debug_Begin();
00566
00567 mlen=3*4+client_TaglistMsgLen(taglist);
00568 if(NULL!=(msg=mem_malloc(mlen)))
00569 {
00570 m=msg;
00571 m=net_MarshalPutLong(m,(u32)window);
00572 m=net_MarshalPutLong(m,gadget_id);
00573 m=net_MarshalPutLong(m,method);
00574 m=net_MarshalPutTaglist(m,taglist);
00575 glw_SendMsg(app->conn,REQ_CCALLGAD,id=client_GetClientId(),(u8 *)msg,mlen);
00576 mem_free(msg);
00577 }
00578
00579 debug_End();
00580
00581 return(id);
00582 }
00583
00584
00585 static void client_TimerClearList(gui_App_t *app, Window_t *win)
00586 {
00587 Node_t *node;
00588 client_Window_t *nwin;
00589 client_Timer_t *ctimer;
00590
00591
00592 debug_Begin();
00593
00594 if(app!=NULL)
00595 {
00596 if(NULL!=(nwin=client_FindWindow(app->windowlist,win)))
00597 {
00598 for(node=list_RemoveNodeHead(nwin->timerlist);node!=NULL;node=list_RemoveNodeHead(nwin->timerlist))
00599 {
00600 ctimer=(client_Timer_t *)list_GetNodeData(node);
00601 glw_TimerCancel((u32)nwin,ctimer->timer);
00602 mem_free(ctimer);
00603 list_DeleteNode(node);
00604 }
00605 list_DeleteList(nwin->timerlist);
00606 }
00607 }
00608
00609 debug_End();
00610 }
00611
00612
00613 static void client_CliARq_CloseWindow(gui_App_t *app, Window_t *win)
00614 {
00615 client_Window_t *nwin;
00616 u8 m[4];
00617
00618 debug_Begin();
00619
00620 if(NULL!=(nwin=client_FindWindow(app->windowlist,win)))
00621 {
00622 nwin->event_handler(app,win,0L,CBK_WINDOW_CLOSED,nwin->userdata);
00623 client_TimerClearList(app,win);
00624 list_RemoveNode(app->windowlist,nwin->node);
00625 list_SetNodeData(nwin->node,NULL);
00626 list_DeleteNode(nwin->node);
00627 if(nwin->name!=NULL) mem_free(nwin->name);
00628 mem_free(nwin);
00629 net_MarshalPutLong(m,(u32)win);
00630 glw_SendMsg(app->conn,REQ_CCLOSEWIN,client_GetClientId(),m,4);
00631 }
00632
00633 debug_End();
00634 }
00635
00636
00637 void client_WinSleep(gui_App_t *app, Window_t *win)
00638 {
00639 u8 m[4];
00640 u32 conn;
00641
00642 debug_Begin();
00643
00644 if(app!=NULL&&win!=NULL)
00645 {
00646 conn=app->conn;
00647 net_MarshalPutLong(m,(u32)win);
00648 glw_SendMsg(conn,REQ_CWINSLEEP,client_GetClientId(),(u8 *)&m,4);
00649 }
00650
00651 debug_End();
00652 }
00653
00654
00655 void client_WinAwake(gui_App_t *app, Window_t *win)
00656 {
00657 u8 m[4];
00658 u32 conn;
00659
00660 debug_Begin();
00661
00662 if(app!=NULL&&win!=NULL)
00663 {
00664 conn=app->conn;
00665 net_MarshalPutLong(m,(u32)win);
00666 glw_SendMsg(conn,REQ_CWINAWAKE,client_GetClientId(),(u8 *)&m,4);
00667 }
00668
00669 debug_End();
00670 }
00671
00672
00673
00674 static Window_t *client_CliSRq_OpenWindowTL(gui_App_t *app, Rect_t *rect, char *window_name, int (*event_handler)(gui_App_t *,Window_t *,u32,int,u32), u32 flags, tag *taglist)
00675 {
00676 client_Window_t *nwin;
00677 Window_t *win=NULL;
00678 Node_t *node;
00679 u8 *msg,*m;
00680 struct glw_ConnUser *cuser;
00681 int mlen,checklist_count=0,i;
00682 gadget_Check_t *checklist=NULL;
00683 tag *t;
00684 u32 id;
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 debug_Begin();
00695
00696 cuser=(struct glw_ConnUser *)app->conn;
00697 if(NULL!=(node=list_CreateNode()))
00698 {
00699 mlen=0;
00700 if(NULL!=(t=tag_FindTag(taglist,TAG_WIN_CHECKLIST)))
00701 {
00702 checklist=(gadget_Check_t *)t->Data;
00703 if(checklist!=NULL) while(checklist[checklist_count].gadget_id!=GADGET_ILLEGAL_ID)
00704 {
00705 mlen+=net_StrMsgLen(checklist[checklist_count].class_name);
00706 checklist_count++;
00707 }
00708 t->Data=(u32)checklist_count;
00709 }
00710 mlen+=net_StrMsgLen(window_name)+4*2+client_TaglistMsgLen(taglist)+(checklist_count*sizeof(gadget_Check_t));
00711 if(NULL!=(msg=mem_malloc(mlen)))
00712 {
00713 m=msg;
00714 if(NULL!=(nwin=mem_calloc(1,sizeof(client_Window_t))))
00715 {
00716 if(NULL!=(nwin->timerlist=list_CreateList()))
00717 {
00718 nwin->userdata=tag_GetTagData(taglist,TAG_WIN_USERDATA,0L);
00719 nwin->name=common_strdup(window_name);
00720 nwin->event_handler=event_handler;
00721 nwin->app=app;
00722 nwin->node=node;
00723 list_SetNodeData(node,nwin);
00724
00725 m=net_MarshalPutLong(m,cuser->app);
00726 m=net_MarshalPutString(m,window_name);
00727 m=net_MarshalPutLong(m,flags);
00728 m=net_MarshalPutTaglist(m,taglist);
00729 for(i=0;i<checklist_count;i++)
00730 {
00731 m=net_MarshalPutLong(m,checklist[i].gadget_id);
00732 m=net_MarshalPutString(m,checklist[i].class_name);
00733
00734 m=net_MarshalPutLong(m,checklist[i].flags);
00735 }
00736
00737 glw_SendMsg(app->conn,REQ_COPENWIN,id=client_GetClientId(),msg,mlen);
00738 cuser->waitfor=REQ_COPENWIN|FL_REPLY;
00739 cuser->userdata=id;
00740 glw_MainLoopCli(app->conn,(u32)app);
00741 win=(Window_t *)net_GetUserData(app->conn);
00742 nwin->window=win;
00743 if(win==NULL)
00744 {
00745 mem_free(nwin);
00746 list_DeleteNode(node);
00747 }
00748 else
00749 {
00750 list_InsertNodeTail(app->windowlist,node);
00751 }
00752 }
00753 }
00754 mem_free(msg);
00755 }
00756 }
00757
00758 debug_End();
00759
00760 return(win);
00761 }
00762
00763
00764 int client_Init(u32 conn, int *byteorder)
00765 {
00766 gui_App_t *app;
00767
00768 debug_Begin();
00769
00770 if(NULL!=(app=mem_malloc(sizeof(gui_App_t))))
00771 {
00772 if(NULL!=(app->windowlist=list_CreateList()))
00773 {
00774 app->conn=conn;
00775 app->name=app_name();
00776 if(0==client_ClientInit(app,byteorder))
00777 {
00778
00779 app->prefs=NULL;
00780 app->locale=NULL;
00781
00782 net_SetState(conn,REQ_SAPP,0L);
00783 glw_MainLoopCli(conn,(u32)app);
00784
00785 if(0==app_Init(app))
00786 {
00787 glw_MainLoopCli(conn,(u32)app);
00788 app_CleanUp(app);
00789 }
00790
00791
00792 client_ClientCleanup(app);
00793 }
00794 list_DeleteList(app->windowlist);
00795 }
00796 mem_free(app);
00797 }
00798
00799 debug_End();
00800
00801 return(0);
00802 }
00803
00804
00805 u32 client_TimerStart(gui_App_t *app, Window_t *win, u32 millisec, int flags, u32 userdata, int (*callback)(Window_t *,u32))
00806 {
00807 client_Window_t *nwin;
00808 client_Timer_t *ctimer=NULL;
00809 Node_t *node;
00810
00811 debug_Begin();
00812
00813 if(NULL!=(nwin=client_FindWindow(app->windowlist,win)))
00814 {
00815 if(NULL!=(ctimer=mem_malloc(sizeof(client_Timer_t))))
00816 {
00817 if(NULL!=(node=list_CreateNode()))
00818 {
00819 ctimer->nwin=nwin;
00820 ctimer->flags=flags;
00821 ctimer->userdata=userdata;
00822 list_SetNodeData(node,ctimer);
00823 list_InsertNodeHead(nwin->timerlist,node);
00824 ctimer->timer=glw_TimerStart((u32)nwin,millisec,(u32)ctimer);
00825 }
00826 }
00827 }
00828
00829 debug_End();
00830
00831 return((u32)ctimer);
00832 }
00833
00834
00835 void client_TimerHandler(u32 timer, u32 userdata)
00836 {
00837 client_Timer_t *ctimer=(client_Timer_t *)userdata;
00838
00839 debug_Begin();
00840
00841 ctimer->nwin->event_handler(ctimer->nwin->app,ctimer->nwin->window,0L,GLWEV_TIMER,ctimer->userdata);
00842 if(ctimer->flags!=0L)
00843 {
00844 }
00845
00846 debug_End();
00847 }
00848
00849
00850 int client_ChangeServer(gui_App_t *app, char *new_server)
00851 {
00852 int port;
00853
00854 debug_Begin();
00855
00856 port=net_GetPort();
00857
00858
00859
00860
00861
00862
00863 debug_End();
00864
00865 return(0);
00866 }
00867
00868
00869 int client_ChangeSkin(gui_App_t *app, Window_t *win, char *skinname)
00870 {
00871 u8 *msg,*m;
00872 u32 conn;
00873 int mlen;
00874
00875 debug_Begin();
00876
00877 if(app!=NULL&&win!=NULL&&skinname!=NULL)
00878 {
00879 conn=app->conn;
00880 mlen=net_StrMsgLen(skinname)+4;
00881 if(NULL!=(m=msg=mem_malloc(mlen)))
00882 {
00883 m=net_MarshalPutLong(m,(u32)win);
00884 net_MarshalPutString(m,skinname);
00885 glw_SendMsg(conn,REQ_CNEWSKIN,client_GetClientId(),(u8 *)msg,mlen);
00886 mem_free(msg);
00887 }
00888 }
00889
00890 debug_End();
00891
00892 return(0);
00893 }