void INThandler(int sig){ char LISTING[MAXLINE]; signal( SIGINT, INThandler ); memset(LISTING, '\0', MAXLINE); printf("\n\nClients LIST --> \n"); if (TYPE == U) { if (sendto(UDPsocket,LISTmsg,strlen(LISTmsg),0,(SA *)&UDPserver,sizeof(UDPserver)) < 0) perror("error in sendto LIST \n"); } if (TYPE == S) { if (sendto(SCTP_Qsocket,LISTmsg,strlen(LISTmsg),0,(SA *)&SCTP_Qserver,sizeof(SCTP_Qserver)) < 0) perror("error in sendto ENDmsg \n"); } if (TYPE == M) { if (sendto(UDPsocket,LISTmsg,strlen(LISTmsg),0,(SA *)&UDPserver,sizeof(UDPserver)) < 0) perror("error in sendto LIST \n"); if ( (bytes = recvfrom(UDPsocket, LISTING, MAXLINE, 0, (SA *) &from, &fromlen) ) < 0) perror("error in recfrom EchoTest UDPsocket \n"); printf("%s\n", LISTING); } selectHandle(); }
// - - - - - - - // GUI STUFF // - - - - - - - void basicShape::keyPressed(ofKeyEventArgs& e){ if(!bEditMode) return; // select another handle ? if( e.key == 91 ){ // 91 = [ selectPrevHandle(); return; } else if( e.key == 93){ // 93 = ] selectNextHandle(); } else if( e.key == OF_KEY_RETURN ){ selectHandle(NULL); } // editActiveHandleWithArrows else if( bEditMode && handleExists(activeHandle) ){ basicPoint translation(0,0); int amplifier = 1 + ofGetKeyPressed(OF_KEY_SHIFT)*10; if( e.key == OF_KEY_DOWN ) translation += basicPoint(0,1); else if( e.key == OF_KEY_UP ) translation += basicPoint(0,-1); else if( e.key == OF_KEY_LEFT ) translation += basicPoint(-1,0); else if( e.key == OF_KEY_RIGHT ) translation += basicPoint(1,0); if(translation.x!=0 || translation.y!=0)translateActiveHandle( translation*amplifier ); } //else ofLogNotice("basicShape::keyPressed()","Unrecognised key: "+ofToString(e.key)); }
bool AspRoi::select(spAspCell_t cell, int x, int y, bool handle) { if(cell == nullAspCell) return false; int oldmouseOver = mouseOver; mouseOver = NOSELECT; selectHandle(cell,x,y, handle); if(oldmouseOver != mouseOver) mouseOverChanged=true; else mouseOverChanged=false; if(mouseOver != NOSELECT) return true; else return false; }
bool basicShape::disableEditMode(){ if( bEditMode ){ // remember bEditMode = false; // clear memory selectHandle(NULL); // recalc some variables //onShapeChanged(); } return (bEditMode==false); }
int AspInteg::select(spAspCell_t cell, int x, int y) { selected = selectHandle(x,y); if(!selected) selected = selectLabel(x,y); if(!selected && x>pCoord[0].x && x<pCoord[1].x) { // select integral line double d = (double)(pCoord[0].x - x)/(double) (pCoord[0].x-pCoord[1].x); int pos = (int) (m_datapts * d) - 1; if(pos>=0 && pos<m_datapts) { int pixy = (int)(cell->val2pix(VERT,(*(m_data+pos))*m_scale) - m_yoff); if(abs(pixy-y) < MARKSIZE) { selectedHandle=0; selected=ROI_SELECTED; } } } return selected; }
wxPalette *wxDIB::CreatePalette() const { // GetDIBColorTable not available in eVC3 #if defined(_WIN32_WCE) && _WIN32_WCE < 400 return NULL; #else wxCHECK_MSG( m_handle, NULL, wxT("wxDIB::CreatePalette(): invalid object") ); DIBSECTION ds; if ( !GetDIBSection(m_handle, &ds) ) { wxLogLastError(wxT("GetObject(hDIB)")); return 0; } // how many colours are we going to have in the palette? DWORD biClrUsed = ds.dsBmih.biClrUsed; if ( !biClrUsed ) { // biClrUsed field might not be set biClrUsed = GetNumberOfColours(ds.dsBmih.biBitCount); } if ( !biClrUsed ) { // bitmaps of this depth don't have palettes at all // // NB: another possibility would be to return // GetStockObject(DEFAULT_PALETTE) or even CreateHalftonePalette()? return NULL; } MemoryHDC hDC; // LOGPALETTE struct has only 1 element in palPalEntry array, we're // going to have biClrUsed of them so add necessary space LOGPALETTE *pPalette = (LOGPALETTE *) malloc(sizeof(LOGPALETTE) + (biClrUsed - 1)*sizeof(PALETTEENTRY)); wxCHECK_MSG( pPalette, NULL, wxT("out of memory") ); // initialize the palette header pPalette->palVersion = 0x300; // magic number, not in docs but works pPalette->palNumEntries = (WORD)biClrUsed; // and the colour table wxCharBuffer rgb(sizeof(RGBQUAD) * biClrUsed); RGBQUAD *pRGB = (RGBQUAD*)rgb.data(); SelectInHDC selectHandle(hDC, m_handle); ::GetDIBColorTable(hDC, 0, biClrUsed, pRGB); for ( DWORD i = 0; i < biClrUsed; i++, pRGB++ ) { pPalette->palPalEntry[i].peRed = pRGB->rgbRed; pPalette->palPalEntry[i].peGreen = pRGB->rgbGreen; pPalette->palPalEntry[i].peBlue = pRGB->rgbBlue; pPalette->palPalEntry[i].peFlags = 0; } HPALETTE hPalette = ::CreatePalette(pPalette); free(pPalette); if ( !hPalette ) { wxLogLastError(wxT("CreatePalette")); return NULL; } wxPalette *palette = new wxPalette; palette->SetHPALETTE((WXHPALETTE)hPalette); return palette; #endif }
void basicShape::selectPrevHandle(){ if( activeHandle==&position ) selectHandle(NULL); else selectHandle( &position ); }
int AspRegion::select(spAspCell_t cell, int x, int y) { selected = selectHandle(x,y); return selected; }
main(int argc, char *argv[]) { FD_SET(0, &full_fd); if (argc != 4) { printf("Usage: ChatClient <host> <port> <m|u|s>\n"); printf("e.g.: ChatClient atria 10123 u \n"); exit(1); } if ((username = getlogin()) == NULL) perror("Who are you?\n"); if ( (hp = gethostbyname(argv[1])) == NULL ) { addr.sin_addr.s_addr = inet_addr(argv[1]); if ((hp = gethostbyaddr((char *) &addr.sin_addr.s_addr, sizeof(addr.sin_addr.s_addr),AF_INET)) == NULL) { fprintf(stderr, "Can't find host %s\n", argv[1]); exit(-1); } } printf("\n UMChatServer --> %s\n", hp->h_name); bcopy ( hp->h_addr, &(TCPserver.sin_addr), hp->h_length); bcopy ( hp->h_addr, &(UDPserver.sin_addr), hp->h_length); bcopy ( hp->h_addr, &(SCTP_Qserver.sin_addr), hp->h_length); printf(" UMChatServer IP: %s \n", inet_ntoa(TCPserver.sin_addr)); SCTP_Qserver.sin_family = AF_INET; TCPserver.sin_family = AF_INET; UDPserver.sin_family = AF_INET; TCPserver.sin_port = htons(atoi(argv[2])); if (strcmp(argv[3], "s") == 0) TYPE=S; if (strcmp(argv[3], "m") == 0) TYPE=M; if (strcmp(argv[3], "u") == 0) TYPE=U; if (TYPE == S) { SCTPsocket = socket (AF_INET,SOCK_STREAM,IPPROTO_SCTP); if ( connect(SCTPsocket, (SA *) &TCPserver, sizeof(TCPserver)) < 0 ) { close(SCTPsocket); perror("connecting to UMChatServer socket"); exit(0); } if ( send(SCTPsocket, username, strlen(username), 0) < 0) perror("send username message"); length = sizeof(client); if ( getsockname (SCTPsocket, (SA *)&client,&length) ) { perror("getting socket name"); exit(0); } SCTPPort = ntohs(client.sin_port); } else { TCP_socket = socket (AF_INET,SOCK_STREAM,0); if ( connect(TCP_socket, (SA *) &TCPserver, sizeof(TCPserver)) < 0 ) { close(TCP_socket); perror("connecting to UMChatServer socket....."); exit(0); } if ( send(TCP_socket, username, strlen(username), 0) < 0) perror("send username message"); length = sizeof(client); if ( getsockname (TCP_socket, (SA *)&client,&length) ) { perror("getting socket name"); exit(0); } TCPPort = ntohs(client.sin_port); } if (TYPE == M) { if ( send(TCP_socket, MChat, strlen(MChat), 0) < 0) perror("send MChat message"); if( (rc=recv(TCP_socket, MIP, sizeof(MIP), 0)) < 0) perror("receiving MIP message"); if (rc > 0) { MIP[rc]='\0'; printf("THE MCAST IP --> %s", MIP); } } if (TYPE == U) { if ( send(TCP_socket, UChat, strlen(UChat), 0) < 0) perror("send UChat message"); } if (TYPE == S) { if( (rc=recv(SCTPsocket, MPort, sizeof(MPort), 0)) < 0) perror("receiving MPort message 01"); if (rc > 0) { MPort[rc]='\0'; printf(" THE MCAST Port --> %s\n", MPort); } strcat(record,inet_ntoa(SCTP_Qserver.sin_addr)); strcat(record,":"); strcat(record,MPort); sprintf(ServerAddr, "[%s] ", record); UDPPort = htons(atoi( MPort ) ); SCTP_Qserver.sin_port = UDPPort; if( (rc=recv(SCTPsocket, RandomCODE1, sizeof(RandomCODE1), 0)) < 0) perror("receiving RandomCODE1 message"); if (rc > 0){ RandomCODE1[rc]='\0'; printf(" THE LIST Code --> %s\n", RandomCODE1); } if( (rc=recv(SCTPsocket, RandomCODE2, sizeof(RandomCODE2), 0)) < 0) perror("receiving RandomCODE2 message"); if (rc > 0){ RandomCODE2[rc]='\0'; printf("THE END Code --> %s\n\n", RandomCODE2); } } else { if( (rc=recv(TCP_socket, MPort, sizeof(MPort), 0)) < 0) perror("receiving MPort message"); if (rc > 0) { MPort[rc]='\0'; printf(" THE MCAST Port --> %s\n", MPort); } strcat(record,inet_ntoa(UDPserver.sin_addr)); strcat(record,":"); strcat(record,MPort); sprintf(ServerAddr, "[%s] ", record); UDPPort = htons(atoi( MPort ) ); UDPserver.sin_port = UDPPort; if( (rc=recv(TCP_socket, RandomCODE1, sizeof(RandomCODE1), 0)) < 0) perror("receiving RandomCODE1 message"); if (rc > 0){ RandomCODE1[rc]='\0'; printf(" THE LIST Code --> %s\n", RandomCODE1); } if( (rc=recv(TCP_socket, RandomCODE2, sizeof(RandomCODE2), 0)) < 0) perror("receiving RandomCODE2 message"); if (rc > 0){ RandomCODE2[rc]='\0'; printf(" THE END Code --> %s\n\n", RandomCODE2); } } LocalHostUS.sin_family = AF_INET; LocalHostUS.sin_port = htons(TCPPort); LocalHostUS.sin_addr.s_addr = htonl(INADDR_ANY); LocalHostSCTP_Q.sin_family = AF_INET; LocalHostSCTP_Q.sin_port = htons(client.sin_port)+1; LocalHostSCTP_Q.sin_addr.s_addr = htonl(INADDR_ANY); MulticastIPAddress = MIP; UDPPort = htons(atoi( MPort ) ); LocalHostUR.sin_family = AF_INET; LocalHostUR.sin_port = UDPPort; LocalHostUR.sin_addr.s_addr = htonl(INADDR_ANY); GroupAddress.sin_family = AF_INET; GroupAddress.sin_port = UDPPort; GroupAddress.sin_addr.s_addr = inet_addr(MulticastIPAddress); if ((UDPsocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) perror("can't create UDP socket S: \n"); if (bind(UDPsocket, (SA *) & LocalHostUS, sizeof(LocalHostUS)) < 0) printf("error in bind UDP S\n"); FD_SET(UDPsocket, &full_fd); if ((SCTP_Qsocket = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) perror("can't create SCTP-Q socket S: \n"); reusePort(SCTP_Qsocket); if (bind(SCTP_Qsocket, (SA *) & LocalHostSCTP_Q, sizeof(LocalHostSCTP_Q)) < 0) printf("error in bind SCTP_Q S\n"); FD_SET(SCTP_Qsocket, &full_fd); if (TYPE == M) { if ((MCASTsocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) perror("can't create UDP MCASTsocket R: \n"); reusePort(MCASTsocket); if (bind(MCASTsocket, (SA *) & LocalHostUR, sizeof(LocalHostUR)) < 0) perror("error in bind R\n"); joinGroup(MCASTsocket, MIP); FD_SET(MCASTsocket, &full_fd); } TimeToLive = 2; setTTLvalue(UDPsocket, &TimeToLive); loop = 1; setLoopback(UDPsocket, loop); signal( SIGQUIT, QUIThandler ); signal( SIGINT, INThandler); char recvBuf[MAXLINE]; int bytes = 0; if (TYPE == U) { if (sendto(UDPsocket,EchoTest,strlen(EchoTest),0,(SA *)&UDPserver,sizeof(UDPserver)) < 0) perror("error in sendto EchoTest UDPsocket \n"); } if (TYPE == S) { char EchoTest[100]; strcpy(EchoTest,"WELCOME, New SCTP: "); strcat(EchoTest,username); strcat(EchoTest,"\n"); if (sendto(SCTP_Qsocket,EchoTest,strlen(EchoTest),0,(SA *)&SCTP_Qserver,sizeof(SCTP_Qserver)) < 0) perror("error in send to EchoTest SCTP_Qsocket \n"); } if (TYPE == M) { if (sendto(UDPsocket,EchoTest,strlen(EchoTest),0,(SA *)&UDPserver,sizeof(UDPserver)) < 0) perror("error in send to EchoTest UDPsocket \n"); if (sendto(MCASTsocket,EchoTest,strlen(EchoTest),0,(SA *)&UDPserver,sizeof(UDPserver)) < 0) perror("error in send to EchoTest MCASTsocket \n"); if ( (bytes = recvfrom(UDPsocket, recvBuf, MAXLINE, 0, (SA *) &from, &fromlen) ) < 0) perror("error in rec from EchoTest UDPsocket \n"); } sleep(1); selectHandle(); }