Если Вы хотите иметь небольшу маску с чатом в Вашей визуализации, то реализация представлена здесь.
Тут мы включаем кое что из библиотеки rllib.
/*************************************************************************** pvapp.h - description ------------------- begin : Sa Aug 5 12:48:27 2006 email : lehrig@t-online.de ***************************************************************************/ #ifndef _PVAPP_H_ #define _PVAPP_H_ #include "processviewserver.h" #include "rleventlogserver.h" #include "rltime.h" // todo: comment me out //#include "rlmodbusclient.h" //#include "rlsiemenstcpclient.h" //#include "rlppiclient.h" //#include "modbusdaemon.h" // this is generated //#include "siemensdaemon.h" // this is generated //#include "ppidaemon.h" // this is generated #define TAR_GZ "/home/lehrig/pvbchat.tar.gz" #define LOGFILE "/var/log/pvbchat.log" int show_mask1(PARAM *p); #endif
*************************************************************************** main.cpp - description ------------------- begin : Sa Aug 5 12:48:27 2006 email : lehrig@t-online.de ***************************************************************************/ #include "pvapp.h" rlEventLogServer eventLogServer(LOGFILE); //<snip...........................>
Программирование чата выполнено в слотах, как показано ниже.
//############################################################### //# mask1_slots.h for ProcessViewServer created: Sat Aug 5 12:55:15 2006 //# please fill out these slots //# here you find all possible events //# Yours: Lehrig Software Engineering //############################################################### // todo: uncomment me if you want to use this data aquisiton // also uncomment this classes in main.cpp and pvapp.h // also remember to uncomment rllib in the project file //extern rlModbusClient modbus; //extern rlSiemensTCPClient siemensTCP; //extern rlPPIClient ppi; extern int num_threads; extern rlEventLogServer eventLogServer; typedef struct // (todo: define your data structure here) { rlTime time; int num, num_threads; char alias[80]; } DATA; static int slotInit(PARAM *p, DATA *d) { if(p == NULL || d == NULL) return -1; //memset(d,0,sizeof(DATA)); d->num = -1; d->num_threads = num_threads; strcpy(d->alias,"unknown"); pvSetText(p,lineEditAlias,"unknown"); pvSetEditable(p,textEditOutput,0); pvPrintf(p,textLabelNumThreads,"Num Users = %d",num_threads); pvSetFontColor(p,textEditOutput,0,255,0); return 0; } static int slotNullEvent(PARAM *p, DATA *d) { if(p == NULL || d == NULL) return -1; const char *cptr; char buf[rlMAX_EVENT]; if(num_threads != d->num_threads) { pvPrintf(p,textLabelNumThreads,"Num Users = %d",num_threads); d->num_threads = num_threads; } while(1) { cptr = eventLogServer.getEvent(buf,&d->num); if(cptr == NULL) break; if(strncmp(cptr,"alias=",6) == 0 && strstr(cptr,"::") != NULL) { pvBeep(p); if(strncmp(&cptr[6],d->alias,strlen(d->alias)) == 0) { pvSetFontColor(p,textEditOutput,0,0,255); // our message } else { pvSetFontColor(p,textEditOutput,255,0,0); } strcpy(buf,"From:"); buf[5] = ':'; pvPrintf(p,textEditOutput,"%s",buf); pvSetFontColor(p,textEditOutput,0,255,0); // message from other user pvBeep(p); } else { pvPrintf(p,textEditOutput,"%s",cptr); } } return 0; } static int slotButtonEvent(PARAM *p, int id, DATA *d) { if(p == NULL || id == 0 || d == NULL) return -1; if(id == pushButtonSend) { pvText(p,textEditInput); // request text } if(id == pushButtonDownload) { pvDownloadFile(p,TAR_GZ); pvMessageBox(p,-1,BoxInformation,"pvbchat.tar.gz downloaded\nto temp directory",1,0,0); } return 0; } static int slotTextEvent(PARAM *p, int id, DATA *d, const char *text) { if(p == NULL || id == 0 || d == NULL || text == NULL) return -1; if(id == lineEditAlias) { if(strlen(text) < (int) (sizeof(d->alias)-1)) { strcpy(d->alias,text); } else printf("text too long:%s\n",text); } return 0; } static int slotClipboardEvent(PARAM *p, int id, DATA *d, int val) { if(p == NULL || id == 0 || d == NULL || val < -1000) return -1; if(id == textEditInput) { char buf[1024]; char *cptr,*cptr_start; d->time.getLocalTime(); sprintf(buf,"alias=%s::%s\n",d->alias,d->time.getTimeString()); eventLogServer.putEvent(buf); cptr = p->clipboard; while(cptr != NULL) { cptr_start = cptr; cptr = strchr(cptr_start,'\n'); if(cptr != NULL) { *cptr = '\0'; cptr++; } if(strlen(cptr_start) > (int) (sizeof(buf)-1)) { eventLogServer.putEvent("this line has been tooooo long\n"); } else { strcpy(buf,cptr_start); strcat(buf,"\n"); eventLogServer.putEvent(buf); } } } return 0; }