コード例 #1
0
ファイル: MSWidget.C プロジェクト: PlanetAPL/a-plus
void MSWidget::event(const XEvent *pEvent_)
{
 if (!_eventOverride||!(*_eventOverride)(pEvent_->type))
  switch (pEvent_->type)
   {
   case Expose:           expose(pEvent_);             break;
   case NoExpose:         noExpose(pEvent_);           break;
   case GraphicsExpose:   graphicsExpose(pEvent_);     break;
   case VisibilityNotify: visibilityNotify(pEvent_);   break;
   case EnterNotify:      if (_server->eventGrabbed(pEvent_,this)==MSTrue) enterNotify(pEvent_);  break;
   case LeaveNotify:      leaveNotify(pEvent_);        break;
   case ConfigureNotify:  configureNotify(pEvent_);    break;
   case CreateNotify:     createNotify(pEvent_);       break;
   case DestroyNotify:    destroyNotify(pEvent_);      break;
   case ReparentNotify:   reparentNotify(pEvent_);     break;
   case MapNotify:        mapNotify(pEvent_);          break;
   case UnmapNotify:      unmapNotify(pEvent_);        break;
   case PropertyNotify:   propertyNotify(pEvent_);     break;
   case SelectionNotify:  selectionNotify(pEvent_);    break;
   case SelectionClear:   selectionClear(pEvent_);     break;
   case SelectionRequest: selectionRequest(pEvent_);   break;
   case ClientMessage:    clientMessage(pEvent_);      break;
   case MotionNotify:     if (_server->eventGrabbed(pEvent_,this)==MSTrue) motionNotify(pEvent_);  break;   
   case ButtonRelease:    if (_server->eventGrabbed(pEvent_,this)==MSTrue) buttonRelease(pEvent_); break;
   case ButtonPress:      if (_server->eventGrabbed(pEvent_,this)==MSTrue) buttonPress(pEvent_);
                          else _server->bell();                                                    break;
   case KeyRelease:       if (_server->eventGrabbed(pEvent_,this)==MSTrue) keyRelease(pEvent_);    break;  
   case KeyPress:         if (_server->eventGrabbed(pEvent_,this)==MSTrue) keyPressEvent(pEvent_);      
                          else _server->bell();                                                    break;
   case FocusIn:          focusInEventNotify(pEvent_);  break;
   case FocusOut:         focusOutEventNotify(pEvent_); break;
   default:                                                                                         break;
   }
  // this event handler is intended to support the mstk builder
  // i.e. it is easier to get events this way rather than
  // subclass every widget and override the event methods
  if (_eventHandler!=0)	(*_eventHandler)(this,pEvent_,_eventHandlerData);
}
bool handleMessageAtTimer(struct message *mapmessage){

	switch(mapmessage->messType){


		// case JOIN:   	Not to be handled
		// case RJOIN:  	Not to be handled
		// case NOTIFY: 	Not to be handled
		// case RCHECK: 	Not to be handled
		// case STATUS: 	Not to be handled
		// case RSTATUS:	Not to be handled
		// case KEEPALIVE:	Not to be handled
		case HELLO:
					{
						/*
						 * If the hellomsg has expired and the (no_of_connection - expired hellos) > minNeighbors
						 * 		I have to close all my current connections and go for soft restart
						 */

						no_of_hello_expired++;
						return true;
					}
				break;

		case CHECK:
				//as Msg time has expired and there was no response from any beacons we need to shut down.
					{
						// Traverse Connection Details and put notify message to its message queue,
						// empty the queue before adding notify message to queue.
						struct notifyMessage *myNotifyMsg = createNotify(0);
						struct message *mymessage;

						mymessage = CreateMessageHeader(NOTIFY, /*Mess Type*/
														1, 		/* TTL */
														myNotifyMsg -> dataLength, /* DataLength Message Body */
														NULL, /* char *messageHeader */
														NULL, /* char *message */
														(void*)myNotifyMsg, /* void *messageStruct */
														NULL,/* char* temp_connectedNeighborsMapKey */
														MYMESSAGE, /* MyMessage or NotMyMessage*/
														ndInfoTimer /*Node Info Pointer*/);

							pthread_mutex_lock(&systemWideLock);
							autoshutdownFlag = 1;
							pthread_mutex_unlock(&systemWideLock);


							pthread_kill(nonBeaconListenerThread,SIGUSR1);


							pthread_mutex_lock(&eventDispatcherQueueLock);
							pthread_cond_signal(&eventDispatcherQueueCV);
							pthread_mutex_unlock(&eventDispatcherQueueLock);


							pthread_mutex_lock(&checkThreadLock);
							pthread_cond_signal(&checkThreadCV);
							pthread_mutex_unlock(&checkThreadLock);

							pthread_kill(keyboardThreadNonbeacon,SIGUSR1);


							connectionDetails *cd;
							pthread_mutex_lock(&connectedNeighborsMapLock);
							for(connectedNeighborsMapIter = connectedNeighborsMap.begin(); connectedNeighborsMapIter != connectedNeighborsMap.end();connectedNeighborsMapIter++)
							{
								cd = connectedNeighborsMapIter->second;
								pthread_mutex_lock(&cd->connectionLock);
								cd->notOperational = 1;
								pthread_mutex_lock(&cd->messagingQueueLock);
								pthread_cond_signal(&cd->messagingQueueCV);
								pthread_mutex_unlock(&cd->messagingQueueLock);
								close(cd->socketDesc);
								pthread_mutex_unlock(&cd->connectionLock);
							}
							pthread_mutex_unlock(&connectedNeighborsMapLock);

							pthread_mutex_lock(&joinMsgMapLock);
							for(joinMsgMapIter = joinMsgMap.begin();joinMsgMapIter!= joinMsgMap.end();joinMsgMapIter++)
							{
								joinMsgMap.erase(joinMsgMapIter->first);
							}
							pthread_mutex_unlock(&joinMsgMapLock);

							pthread_mutex_lock(&helloMsgMapLock);
							for(helloMsgMapIter = helloMsgMap.begin();helloMsgMapIter != helloMsgMap.end();helloMsgMapIter++)
							{
								helloMsgMap.erase(helloMsgMapIter->first);
							}
							pthread_mutex_unlock(&helloMsgMapLock);

							pthread_mutex_lock(&systemWideLock);
							restartState = 1;
							pthread_mutex_unlock(&systemWideLock);
						return false;
					}
					break;
		case SEARCH:
					{
						pthread_mutex_lock(&keyboardLock);
						pthread_cond_signal(&keyboardCV);
						pthread_mutex_unlock(&keyboardLock);
					}
					break;
		default:
				{//Error - Message Type not defined

					return false;
				}
	}

	return true;
}
コード例 #3
0
ファイル: client.c プロジェクト: openremote/pad
	if (*tx != NULL)
		return R_TX_RUNNING;
	*tx = apr_palloc(pool, sizeof(clientTransaction_t));
	(*tx)->request = NULL;
	(*tx)->response = NULL;
	return R_SUCCESS;
}

void clearClientTransaction(apr_pool_t *pool, clientTransaction_t **tx) {
	apr_pool_clear(pool);
	*tx = NULL;
}

int operatePortData(clientTransaction_t *tx, apr_pool_t *txPool, char *portId, char *buf, int len) {
	// Create notify message to send to client
	CHECK(createNotify(txPool, &tx->request, portId, buf, len))
	return R_SUCCESS;
}

int operateResponse(apr_socket_t *sock, clientTransaction_t *tx, apr_pool_t *txPool, char code) {
	CHECK(readBody(sock, &tx->response, txPool, code))

	switch (tx->response->code) {
	case ACK:
		// TODO check ACK code
		break;
	default:
		return R_UNEXPECTED_RESP;
	}

	return R_SUCCESS;