Beispiel #1
0
ssize_t nextMessage(struct AddrFilter const filter, ssize_t const socket,
                    char * * const buf, size_t * const buf_len){
	ssize_t len = recv(socket, *buf, *buf_len, MSG_TRUNC);
	if (len <= 0 ) {
		// Error
		return len;
	} else if ((size_t) len > *buf_len){
		// Reallocate with sufficient size
		*buf_len = (size_t) len;
		free(*buf);
		*buf = malloc(*buf_len);

		// clear socket, else get EBUSY on requestAddr
		while (recv(socket, *buf, *buf_len, MSG_DONTWAIT) != -1)
			continue;
		if (errno != EAGAIN && errno != EWOULDBLOCK)
			return -1;

		if (!requestAddr(filter, socket))
			return -1;

		return nextMessage(filter, socket, buf, buf_len);
	} else {
		return len;
	}
}
Beispiel #2
0
bool NetSwitchInternalBuffer::removeMessage ( void ) {
  MessageStateList
  * msl = currMessage;

  assert ( msl != NULL );

  buffersUsed[msl->msg->networkVC]--;

  // Buffer occupancy statistics
  msl->msg->atHeadTime += currTime;
  msl->msg->bufferTime += currTime;

  if ( msl->next == NULL ) {
    ageBufferTail[msl->msg->networkVC] = msl->prev;
  } else {
    msl->next->prev = msl->prev;
  }

  if ( msl->prev == NULL ) {
    ageBufferHead[msl->msg->networkVC] = msl->next;
  } else {
    msl->prev->next = msl->next;
  }

  nextMessage();

  freeMessageStateList ( msl );

  return false;
}
void MonitoringDevice::commandGetEvent(unsigned char* _pArea){
	const unsigned int EVENT_ID_OFFSET = 5;
	const unsigned int EVENT_FAULT_OFFSET = 7;
	const unsigned int EVENT_COUNT_OFFSET = 8;

	setFault(_pArea[EVENT_FAULT_OFFSET]);

	unsigned short _eventId = _pArea[EVENT_ID_OFFSET] + _pArea[EVENT_ID_OFFSET + 1] * 256;
	if (_eventId != eventId){
		if (_pArea[EVENT_COUNT_OFFSET] != 0){
			if (!SerialDebug::getSingleton().isOn())
				redirectToPc(_pArea);

			unsigned int messageCount = firstMessage(&_pArea);
			for (unsigned int i = 0; i < messageCount; ++i){
				if (isEventMessage(_pArea)){
					toLog(_pArea);
					setOutputs(_pArea);
				}

				nextMessage(&_pArea);
			}
		}
	}

	eventId = _eventId;
}
void DirectionOfMovement::SendContainer()
{
  opendlv::model::Direction direction(0.0f, 0.0f);
  opendlv::sensation::DirectionOfMovement nextMessage(direction);
  odcore::data::Container c(nextMessage);
  getConference().send(c);
}
Beispiel #5
0
void Log::newline() {
    record("\n"); //Record it/add to buffer.
    int old = newline_mode; //Save the old newline mode.
    newlmode(1); //Set the newlines to one.
    nextMessage(); //Write out the buffer. NOT going for the next message.
    newlmode(old); //Reset newline_mode to original value (should be 2).
    logged_since_last_message = true; //Something was just logged, so...
}
Beispiel #6
0
// Returns AF_MAX (with errno set) if error, AF_UNSPEC if no more addrs (socket closed)
struct IPAddr nextAddr(struct AddrFilter const filter, struct MonitorState * const state){
	// NLMSG_OK checks length first, so safe to call with state->nlh == NULL iff
	// state->nlmsg_len < (int) sizeof(struct nlmsghdr)
	if (NLMSG_OK(state->nlh, state->nlmsg_len) && (state->nlh->nlmsg_type != NLMSG_DONE)){
		struct nlmsghdr * nlh = state->nlh;
		state->nlh = NLMSG_NEXT(state->nlh, state->nlmsg_len);
		switch(nlh->nlmsg_type){
		case NLMSG_ERROR:
			errno = -((struct nlmsgerr *) NLMSG_DATA(nlh))->error;
			struct IPAddr addr = {.af = AF_MAX};
			return addr;
		case RTM_NEWADDR: {
			struct ifaddrmsg * ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh);
			if (!filterIfAddrMsg(*ifa, filter))
				return nextAddr(filter, state);
			{
			struct rtattr * rth;
			size_t rtmsg_len;
			for (rth = IFA_RTA(ifa), rtmsg_len = IFA_PAYLOAD(nlh);
			     RTA_OK(rth, rtmsg_len); RTA_NEXT(rth, rtmsg_len)){
				if (rth->rta_type != IFA_ADDRESS)
					continue;
				// family checked in filterIfAddrMsg, so always valid.
				struct IPAddr addr = {.af = ifa->ifa_family};
				switch (ifa->ifa_family) {
				case AF_INET:
					addr.ipv4 = *((struct in_addr *) RTA_DATA(rth));
					break;
				case AF_INET6:
					addr.ipv6 = *((struct in6_addr *) RTA_DATA(rth));
					break;
				}
				if (addrIsPrivate(addr) && !filter.allow_private)
					return nextAddr(filter, state);
				else
					return addr;
			}
			}
			// Recieved RTM_NEWADDR without any address.
			errno = EBADMSG;
			struct IPAddr addr = {.af = AF_MAX};
			return addr;
		}
		default:
			return nextAddr(filter, state);
		}
	} else {
		state->nlmsg_len = nextMessage(filter, state->socket, &state->buf, &state->buf_len);
		if (state->nlmsg_len == 0) {
			// Socket closed by kernel
			struct IPAddr addr = {.af = AF_UNSPEC};
			return addr;
		} else if (state->nlmsg_len < 0) {
			// Socket error
			struct IPAddr addr = {.af = AF_MAX};
			return addr;
		} else  {
Beispiel #7
0
/**
 * Receives raw vehicle message from proxy.
 * Sends raw vehicle message to linguistics handlers.
 */
void Audition::nextContainer(odcore::data::Container &c)
{
  // cout << "Received container of type " << c.getDataType() 
  //     << " sent at " << c.getSentTimeStamp().getYYYYMMDD_HHMMSSms() 
  //     <<" received at " << c.getReceivedTimeStamp().getYYYYMMDD_HHMMSSms()
  //     << endl;
  if(c.getDataType() == opendlv::proxy::V2vInbound::ID()){
    // std::cout << "Received a message of type ."
    opendlv::proxy::V2vInbound message = c.getData<opendlv::proxy::V2vInbound>();
    std::string dataString = message.getData();
    std::vector<unsigned char> data(dataString.begin(), dataString.end());
    
    // string value = message.getValue();
    // vector<string> tokens = odcore::strings::StringToolbox::split(value, '|');


    // std::cout << std::to_string(static_cast<unsigned char>(*data.begin())) 
    //     << std::endl;
    // std::vector<unsigned char> const bytes = data;
    // std::stringstream ss;
    // for (uint i = 0; i < bytes.size(); i++) {
    //     ss << std::to_string(bytes.at(i));
    //     ss << "|";
    // }
    // std::cout<<ss.str()<<std::endl;
    // std::cout<<value<<std::endl;

    unsigned char v2vMsgId = data.at(0);
    // std::cout <<  std::to_string(v2vMsgId)<<std::endl;
    std::string v2vMsgType;
    switch(v2vMsgId)
    {
      case 1:
        v2vMsgType = "denm";
      break;
      case 2:
        v2vMsgType = "cam";
      break;
      case 10:
        v2vMsgType = "iclcm";
      break;
      default:
        std::cout << "Received invalid message ID.";
    }
    if(!v2vMsgType.empty())
    {
      // std::cout<<"Sorted and sending to next layer.\n";
      opendlv::sensation::Voice nextMessage(v2vMsgType, message.getSize(), dataString);
      odcore::data::Container container(nextMessage);
      getConference().send(container);
    }

  }
}
Beispiel #8
0
/**
 * Mandatory TableStreamContext override.
 */
int64_t RecoveryContext::handleStreamMore(TupleOutputStreamProcessor &outputStreams,
                                          std::vector<int> &retPositions) {
    if (outputStreams.size() != 1) {
        throwFatalException("RecoveryContext::handleStreamMore: Expect 1 output stream "
                            "for recovery, received %ld", outputStreams.size());
    }
    /*
     * Table ids don't change during recovery because
     * catalog changes are not allowed.
     */
    bool hasMore = nextMessage(&outputStreams[0]);
    // Non-zero if some tuples remain, we're just not sure how many.
    int64_t remaining = (hasMore ? 1 : 0);
    for (size_t i = 0; i < outputStreams.size(); i++) {
        retPositions.push_back((int)outputStreams.at(i).position());
    }
    return remaining;
}
void OpticalFlow::SendContainer()
{
  uint16_t numberOfPoints = m_staticImagePoints.size();
  std::vector<opendlv::model::Direction> directions;
  std::vector<float> u;
  std::vector<float> v;
  for(uint8_t i = 0; i < m_staticImagePoints.size(); i++){
    // std::cout<< m_staticImagePoints[i].x << std::endl;
    float x = m_staticImagePoints[i].x;
    float y = m_staticImagePoints[i].y;
    opendlv::model::Direction direction(x, y);

    directions.push_back(direction);
    u.push_back(m_endImagePoints[i].x - x);
    v.push_back(m_endImagePoints[i].y - y);
  }
  opendlv::sensation::OpticalFlow nextMessage(numberOfPoints, directions, u, v);
  odcore::data::Container c(nextMessage);
  getConference().send(c);
}
Beispiel #10
0
    // Returns the next message to deliver
    // \returns the next message, or NULL if the queue is empty
    Message* front(Key* keyAtFront) {
        Message* result = NULL;

        if (mFrontQueue == NULL) {
            Time vftime(Time::null());
            nextMessage(&result, &vftime, &mFrontQueue);
        }
        else { // Otherwise, just fill in the information we need from the marked queue
            assert(!mFrontQueue->messageQueue->empty());
            result = mFrontQueue->nextFinishMessage;
            assert(result == mFrontQueue->messageQueue->front());
        }

        if (result != NULL) {
            *keyAtFront = mFrontQueue->key;
            assert(mFrontQueue->enabled);
            return result;
        }

        return NULL;
    }
Beispiel #11
0
    // Returns the next message to deliver
    // \returns the next message, or NULL if the queue is empty
    Message* pop(Key* keyAtFront = NULL) {
        Message* result = NULL;
        Time vftime(Time::null());

        // If we haven't marked any queue as holding the front item, do so now
        if (mFrontQueue == NULL)
            nextMessage(&result, &vftime, &mFrontQueue);
        else { // Otherwise, just fill in the information we need from the marked queue
            assert(!mFrontQueue->messageQueue->empty());
            result = mFrontQueue->nextFinishMessage;
            assert(result == mFrontQueue->messageQueue->front());
            vftime = mFrontQueue->nextFinishTime;
        }

        if (result != NULL) {
            // Note: we may have skipped a msg using the predicate, so we use max here to make sure
            // the virtual time increases monotonically.
            mCurrentVirtualTime = std::max(vftime, mCurrentVirtualTime);

            assert(mFrontQueue != NULL);
            assert(mFrontQueue->enabled);

            if (keyAtFront != NULL)
                *keyAtFront = mFrontQueue->key;

            Message* popped_val = mFrontQueue->messageQueue->pop();
            assert(popped_val == mFrontQueue->nextFinishMessage);
            assert(popped_val == result);

            // Remove from queue time list
            removeFromTimeIndex(mFrontQueue);
            // Update finish time and add back to time index if necessary
            computeNextFinishTime(mFrontQueue, vftime);

            // Unmark the queue as being in front
            mFrontQueue = NULL;
        }

        return result;
    }
Beispiel #12
0
/*other is either "trusted/untrusted" or a number */
int main(int argc, char*argv[]) {
	char *buffer=(char*)malloc(50*sizeof(char)), 
		*name=(char*)malloc(15*sizeof(char)), 
		*action=(char*)malloc(15*sizeof(char)), 
		*other=(char*)malloc(15*sizeof(char)); 
	FILE *fp = fopen(argv[1], "r");
	if (fp==NULL) {
		printf("error opening file");
		return 1;
	}
	Table *t= lookup_mkTable(); 
	while ((buffer=nextMessage(fp))!=NULL) {
		sscanf(buffer, " %s %s %s", name, action, other);
		if (strcmp(action, "joins")==0) 
				join(t, name, other);
		if (strcmp(action, "deposits")==0)
			deposit(t, name, atoi(other));
		if (strcmp(action, "withdraws")==0)
			withdraw(t, name, atoi(other));
		if (strcmp(action, "print")==0)
			print(t, name);
	} 
	return 0;
}
MainWindow::MainWindow(QtSingleApplication &app)
	: QMainWindow(NULL, MAINWINDOWFLAGS), 
	  isLoggingOn(false), isShuttingDown(false), 
	  showWelcomeScreen(false), isInviteCodeNeed(false), isMousePressed(false), showClipartWindow(false),
	  widgetIndexBeforeWaiting(-1),
	  contactList(NULL), drawingWindow(NULL), historyWindow(NULL), 
	  trayIcon(0), trayMenu(NULL), trayClickTimer(-1), trayConnectingTimer(-1), 	
	  autoUpdater(this), http(NULL), reply(NULL)
{
   // AEInstallEventHandler(
    
	setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);

	TimeMeasure t("MainWindow");

	progressDialog = NULL;

	setupUi(this);

	t.showTimePassedAfterSetupUi();

	// connect signals from second copy of the application
	connect(&app, SIGNAL(messageReceived(const QString & )), this, SLOT(showWindow()));

	isPlaySounds = ProgramSettings::getPlaySouns();

	// Connect infomanager & server
	connect(INFOMANAGER, SIGNAL(userAccountUpdated()), this, SLOT(onUserAccountUpdated()));
	connect(INFOMANAGER, SIGNAL(userStatusChanged(UserStatus::UserStatusEnum)), this, SLOT(onUserStatusChanged(UserStatus::UserStatusEnum)));

	connect(SERVER, SIGNAL(serverError(ServerResponseHandler::ServerError)), this, SLOT(onServerError(ServerResponseHandler::ServerError)));
	connect(SERVER, SIGNAL(logoutCompleted()), this, SLOT(onLogoutCompleted()));

	// Connect message manager
	connect(MESSAGEMANAGER, SIGNAL(privateMessageReceived(qint32, const MessageKey &)), this, SLOT(onPrivateMessageReceived(qint32, const MessageKey &)));
	connect(MESSAGEMANAGER, SIGNAL(friendsMessageReceived(const MessageKey &)), this, SLOT(onFriendsMessageReceived(const MessageKey &)));
	connect(MESSAGEMANAGER, SIGNAL(channelMessageReceived(qint32, const MessageKey &)), this, SLOT(onChannelMessageReceived(qint32, const MessageKey &)));
	connect(MESSAGEMANAGER, SIGNAL(showExceptionDialogSendingMessage(ContactResultCode::ContactResultCodeEnum, qint32)), this, SLOT(onShowExceptionDialogSendingMessage(ContactResultCode::ContactResultCodeEnum, qint32)));
		
	// Connect logon
	connect(logonWidget, SIGNAL(registerNewUser()), this, SLOT(showRegistrationWidget()));
	connect(logonWidget, SIGNAL(inviteCodeNeeded()), this, SLOT(onInviteCodeNeeded()));
	connect(logonWidget, SIGNAL(forgotPassword()), this, SLOT(showForgotPasswordWidget()));
	connect(logonWidget, SIGNAL(logonStarted()), this, SLOT(onLogonStarted()));
	connect(logonWidget, SIGNAL(logonStopped()), this, SLOT(onLogonStopped()));
	connect(logonWidget, SIGNAL(successLogon()), this, SLOT(onLogonSuccess()));
	connect(logonWidget, SIGNAL(showSettings()), this, SLOT(showSettings()));

	// connect widgets with waiting widget
	connect(waitingWidget, SIGNAL(cancel()), this, SLOT(cancelWaitingWidget()));
	connect(logonWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget()));
	connect(logonWidget, SIGNAL(waitingStop()), this, SLOT(stopWaitingWidget()));
	connect(registrationWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget()));
	connect(registrationWidget, SIGNAL(waitingHide()), this, SLOT(cancelWaitingWidget()));
	connect(forgotPasswordWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget()));
	connect(forgotPasswordWidget, SIGNAL(waitingStop()), this, SLOT(cancelWaitingWidget()));
	connect(inviteCodeWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget()));
	connect(inviteCodeWidget, SIGNAL(waitingStop()), this, SLOT(cancelWaitingWidget()));

	// Connect invite
	connect(inviteCodeWidget, SIGNAL(next()), this, SLOT(onInviteCodeAccepted()));
	connect(inviteCodeWidget, SIGNAL(back()), this, SLOT(showLogonWidget()));

	// Connect registration
	connect(registrationWidget, SIGNAL(back()), this, SLOT(onRegistrationBack()));
	connect(registrationWidget, SIGNAL(registrationSuccess()), this, SLOT(onRegistrationSuccess()));

	// Connect info
	connect(infoWidget, SIGNAL(finished()), this, SLOT(showLogonWidget()));

	// Connect forgot password
	connect(forgotPasswordWidget, SIGNAL(finished()), this, SLOT(onResetPassword()));
	connect(forgotPasswordWidget, SIGNAL(back()), this, SLOT(showLogonWidget()));

	// Connect welcome
	connect(welcomeWidget, SIGNAL(finished()), this, SLOT(showTvWidget()));

	// Connect buttons
	connect(tvCloseButton, SIGNAL(clicked()), this, SLOT(close()));

	// Connect TVWidget
	connect(previousButton, SIGNAL(clicked()), tvWidget, SLOT(previousMessage()));
	connect(tvWidget, SIGNAL(previousMessageAvailable(bool)), previousButton, SLOT(setEnabled(bool)));
	connect(tvWidget, SIGNAL(previousMessageAvailable(bool)), this, SLOT(showTvWidget()));
	
	connect(nextButton, SIGNAL(clicked()), tvWidget, SLOT(nextMessage()));
	connect(tvWidget, SIGNAL(nextMessageAvailable(bool)), nextButton, SLOT(setEnabled(bool)));
	connect(tvWidget, SIGNAL(nextMessageAvailable(bool)), this, SLOT(showTvWidget()));

	connect(tvWidget, SIGNAL(replyRequest(const QImage &)), this, SLOT(onReply(const QImage &)));

	tvWidget->setChatLabel(tr(ALL_FRIENDS_CHAT_LABEL));

	// Init variables & windows
	autoUpdater.startCheckingPaused();
	connect(&autoUpdater, SIGNAL(downloadNewVersion()), this, SLOT(onDownloadNewVersion()));

	clipartWindow = new ClipartWindow(this);

	createChildWindows();

	loadSettings();

	// start logon
	showLogonWidget(true);
	logonWidget->start(true);

	buttonsFrame->hide();

	setupTray();
	updateWindowTitle();

	// show help by pressing F1
	QShortcut * showHelpShortCut = new QShortcut(this);
	showHelpShortCut->setKey(Qt::Key_F1);
	connect(showHelpShortCut, SIGNAL(activated()), this, SLOT(showHelp()));
    
#ifdef Q_WS_MAC
    macInit();
#endif
}
Beispiel #14
0
void MainState::updateFrame() {
    play();

    _inputs.sync();

    if(_debugInput->justPressed()) {
        _state = GAME_OVER;
        _menuStack.clear();
    }

    if(!_messages.empty()) {
        if(_menuInputs.ok->justPressed()
                || _menuInputs.cancel->justPressed()) {
            nextMessage();
        }
    } else if(!_menuStack.empty()) {
        _menuStack.back()->update();
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    _game->renderer()->mainBatch().clearBuffers();

    _entities.updateWorldTransform();
    _sprites.render(_loop.frameInterp(), _camera);
    _texts.render(  _loop.frameInterp(), _game->renderer());
    _anims.update(_loop.tickDuration());

    _statusFrame->render(_game->renderer());

    if(_messages.empty()) {
        for(Menu* menu: _menuStack) {
            menu->render(_game->renderer());
        }
    } else {
        _messageFrame->render(_game->renderer());

        _font->render(_game->renderer(),
                      Vector3(_messageOutMargin + _messageMargin,
                              _messageTextHeight, 0.95),
                      Vector4(1, 1, 1, 1),
                      _messages.front());
    }

    _game->renderer()->spriteShader()->use();
    _game->renderer()->spriteShader()->setTextureUnit(0);
    _game->renderer()->spriteShader()->setViewMatrix(_camera.transform());
    _game->renderer()->mainBatch().render();

    _game->window()->swapBuffers();

    uint64 now = _game->sys()->getTimeNs();
    ++_fpsCount;
    if(_fpsCount == 60) {
        log().info("Fps: ", _fpsCount * 1000000000. / (now - _fpsTime));
        _fpsTime  = now;
        _fpsCount = 0;
    }

    LAIR_LOG_OPENGL_ERRORS_TO(log());
}
Beispiel #15
0
int MessageState::getMessage(int module, MessageTuple &t, reg_t buf) {
	_cursorStack.init(module, t);
	return nextMessage(buf);
}