Exemple #1
0
int main(int argc,char *argv[],char *envp[])
{

  int fdA,fdB,fdDelayA,fdDelayB;
  int status;
  char *bufferA,*bufferB;
  pid_t pid;

  pagesize = getpagesize();

  if ((prepareFile("A",&fdA))
      || (prepareFile("B",&fdB))
      || (prepareFile("DelayA",&fdDelayA))
      || (prepareFile("DelayB",&fdDelayB))
      || (mapBuffer(&bufferA,fdDelayA,fdB))
      || (mapBuffer(&bufferB,fdDelayB,fdA)))
    exit(1);
  
  pid = fork();

  if (pid == 0)
    {
      status = startIO(fdA,bufferA);
      exit(status);
    }

  if (pid == -1)
    {
      exit(1);
    }
  status = startIO(fdB,bufferB);
  exit(status);

}
void Network::connectToServer(const char* p_URL, unsigned short p_Port, actionDoneCallback p_DoneHandler, void* p_UserData)
{
	NetworkLogger::log(NetworkLogger::Level::INFO, "Connecting to server");

	m_ClientConnection.reset();
	m_ClientConnect.reset();
	m_IO_Service.reset();

	if (m_IO_Thread.joinable())
	{
		m_IO_Thread.join();
	}

	m_ClientConnect.reset(new ClientConnect(m_IO_Service, p_URL, p_Port, std::bind(&Network::clientConnectionDone, this, std::placeholders::_1, p_DoneHandler, p_UserData)));

	startIO();
}
void BCSPImplementation::runStack()
{
    //here's where we actually run round in a loop calling the scheduler...
    while(!mStackMustDie)
    {
        uint32 timeNow = ms_clock() ;
        uint32 wakeupTime = scheduler(mStack,timeNow) ;
        //now see if we can do anything with the uart...
        //try sending ...
        if(!mXMITBusy) 
        {
            //copy stuff out of stack output buffer 
            mXMITBytesAvailable = numBytesInTransmitBuffer(mStack) ;
            if (mXMITBytesAvailable)
            {
                readFromTransmitBuffer(mStack,mXMITBuffer, mXMITBytesAvailable) ;
                if (mXMITBytesAvailable) 
                {
                    BTRACE0(IO,"-->") ;
                    for (unsigned int c = 0 ; c < mXMITBytesAvailable ; c++)
                        PLAINBTRACE1(IO," %02x",mXMITBuffer[c]) ;
                    PLAINBTRACE0(IO,"\n") ;
                }
            }
        }

        //now startup I/O  - non-zero indicates that the read or write has returned immediately
        if (!startIO() && isStackIdle(mStack))
                wait(wakeupTime) ;

        //now try loading the stack receive buffer
        if (mRCVBytesAvailable &&(mRCVBytesAvailable <= numFreeSlotsInReceiveBuffer(mStack)))
        {
            if (mRCVBytesAvailable) 
            {
                BTRACE0(IO,"<--") ;
                for (unsigned int c = 0 ; c < mRCVBytesAvailable ; c++) PLAINBTRACE1(IO," %02x",mRCVBuffer[c]) ;
                PLAINBTRACE0(IO,"\n") ;
            }
            writeToReceiveBuffer(mStack,mRCVBuffer,(uint8) mRCVBytesAvailable) ;
            mRCVBytesAvailable = 0 ;
        }
    }
    //we'll return if we get the stackmustdie signal
} 
Exemple #4
0
void ControlReaderThread::handleEvent(struct usb_functionfs_event *event)
{
    MTP_LOG_INFO("Event: " << event_names[event->type]);
    switch(event->type) {
    case FUNCTIONFS_ENABLE:
    case FUNCTIONFS_RESUME:
        emit startIO();
        break;
    case FUNCTIONFS_DISABLE:
    case FUNCTIONFS_SUSPEND:
        emit stopIO();
        break;
    case FUNCTIONFS_SETUP:
        setupRequest((void*)event);
        break;
    default:
        break;
    }
}
Exemple #5
0
	void Component::run()
	{
		try {
			std::cerr << "starting component " << name << "..." << std::endl;
			startIO();
			std::cerr << "    ... " << name << " ready." << std::endl;
		} catch (std::exception & ex) {
			log->error("Cannot startup component:", &ex);
			try {
				state = STATE_FAILURE;
				meta.reportState(state, "Cannot startup component:", &ex);
			} catch (CMSException & me) {
				log->error("cannot report failure state", & me);
			}
			requestExit();
		}

		while (!exitRequested()) {
			// Report that we are alive before we check system ready status,
			// (in case we were stalled due to a long act() or react() this
			// means we "report back" to the rest of the system)
			meta.IamAlive();
      //printf("run %i\n",exitRequested());
			// Check at every loop that the total system is ready
			bool exitFlag = false;
			synchronized (&meta) {
				if (!meta.isSystemReady()) {
					log->info("waiting for system to become ready");
				}
				while (!meta.isSystemReady()) {
					try {
						meta.wait(1000);
					} catch (decaf::lang::Exception & ie) {
						ie.printStackTrace();
					}
					if (meta.isSystemReady()) {
						log->info("system ready - let's go");
					}
					if (exitRequested()) {
						exitFlag = true;
						break;
					}
				}
			}
			if (exitFlag) break;

			try {
				// Check if we should do something proactively:
				long long before = System::currentTimeMillis();
				act();
				long long timeSpentInAct = System::currentTimeMillis() - before;
				meta.statistics()->actTime((long)timeSpentInAct);
			} catch (std::exception & e) {
				log->error("error when trying to act", & e);
				try {
					state = STATE_FAILURE;
					meta.reportState(state, "error when trying to act", &e);
				} catch (CMSException & me) {
					log->error("cannot report failure state", & me);
				}
				requestExit();
				return;
			}

			Receiver * r = NULL;
			synchronized (&mutex) {
				if (inputWaiting.empty()) {
				// block until input becomes available
				mutex.wait(waitingTime);
				}
				// check again
				if (!inputWaiting.empty()) {
					r = inputWaiting.front();
					inputWaiting.pop();
				}
			}
			if (r == NULL) continue;
			//assert(receivers.contains(r)); // the receiver that alerted us is not one of our receivers;
			SEMAINEMessage * message = r->getMessage();
			assert(message != NULL); // Receiver alerted me but has no message
			meta.statistics()->countMessageReceived();

			try {
				// time that the message travelled, in "user" time (ms since system startup -- this should be independent of clock asynchrony)
				long long timeMessageTravelled = meta.getTime() - message->getUsertime();
				meta.statistics()->transmitTime((long)timeMessageTravelled);
				// Now, do something meaningful with the message,
				// and possibly send output via the Senders.
				long long before = System::currentTimeMillis();
				react(message);
				delete message;
				long long timeSpentInReact = System::currentTimeMillis() - before;
				meta.statistics()->reactTime((long)timeSpentInReact);
			} catch (std::exception & e) {
				log->error("error when trying to react", &e);
				try {
					state = STATE_FAILURE;
					std::string errMsg = CMSLogger::toLogMessageText("error when trying to react", &e)
						+ "(message was: " + CMSLogger::message2logString(message) + ")";
					meta.reportState(state, errMsg);
				} catch (CMSException & me) {
					log->error("cannot report failure state", & me);
				}
				requestExit();
				return;
			}
		}
	}