Beispiel #1
0
void MenuSystem::setState(state_t state)
{
  //Serial.print("$HMLG,0,Setting state: ");
  //Serial.println(state, DEC);
  m_lastState = m_state;

  while (state > ST_VMAX && state != m_state)
  {
    handler_t handler = getHandler();
    if (handler)
      handler(BUTTON_LEAVE);

    m_state = state;
    m_currMenu = m_definitions;

    state_t lookup;
    while ((lookup = pgm_read_byte(&m_currMenu->state)))
    {
      if (lookup == m_state)
        break;
      ++m_currMenu;
    }
    
    if (m_currMenu)
    {
      handler = getHandler();
      if (handler)
        state = handler(BUTTON_ENTER);
    } else {
      state = ST_NONE;
    }
  }  // while state changing

  m_lastActivity = millis();
}
Beispiel #2
0
// virtual
CXMLHandler * ModelValueHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  const char * Name;
  const char * simulationType;
  CModelEntity::Status SimulationType;
  bool AddNoise;

  switch (mCurrentElement.first)
    {
      case ModelValue:
        mKey = mpParser->getAttributeValue("key", papszAttrs);
        Name = mpParser->getAttributeValue("name", papszAttrs);
        simulationType = mpParser->getAttributeValue("simulationType", papszAttrs, false);

        // We need to handle old files which used the attribute status.
        if (!simulationType)
          {
            simulationType = mpParser->getAttributeValue("status", papszAttrs, false);

            if (!simulationType) // status and simulationType are both missing
              simulationType = mpParser->getAttributeValue("simulationType", papszAttrs);
          }

        SimulationType = toEnum(simulationType, CModelEntity::XMLStatus, CModelEntity::FIXED);
        AddNoise = mpParser->toBool(mpParser->getAttributeValue("addNoise", papszAttrs, "false"));

        mpMV = new CModelValue();
        addFix(mKey, mpMV);
        mpMV->setObjectName(Name);
        mpMV->setStatus(SimulationType);
        mpMV->setAddNoise(AddNoise);

        mpData->pModel->getModelValues().add(mpMV, true);
        break;

      case MiriamAnnotation:
      case Comment:
      case Expression:
      case MathML:
      case InitialExpression:
      case NoiseExpression:
      case Unit:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case ListOfUnsupportedAnnotations:
        mpData->mUnsupportedAnnotations.clear();
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
Beispiel #3
0
// virtual
CXMLHandler * TaskHandler::processStart(const XML_Char * pszName,
                                        const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  const char * Key;
  const char * type;
  CTaskEnum::Task Type;
  bool Scheduled = false;
  bool UpdateModel = false;

  switch (mCurrentElement.first)
    {
      case Task:
        mpData->pCurrentTask = NULL;

        Key = mpParser->getAttributeValue("key", papszAttrs, false);
        type = mpParser->getAttributeValue("type", papszAttrs);
        Type = toEnum(type, CTaskEnum::TaskXML, CTaskEnum::UnsetTask);
        Scheduled = mpParser->toBool(mpParser->getAttributeValue("scheduled", papszAttrs, "false"));
        UpdateModel = mpParser->toBool(mpParser->getAttributeValue("updateModel", papszAttrs, "false"));

        mpData->pCurrentTask = CTaskFactory::createTask(Type, mpData->pTaskList);

        if (mpData->pCurrentTask != NULL)
          {
            mpData->pCurrentTask->setScheduled(Scheduled);
            mpData->pCurrentTask->setUpdateModel(UpdateModel);
            mpData->pCurrentTask->setMathContainer(&mpData->pModel->getMathContainer());

            if (Key != NULL)
              {
                addFix(Key, mpData->pCurrentTask);
              }
          }
        else
          {
            CCopasiMessage(CCopasiMessage::WARNING, MCXML + 5, type, mpParser->getCurrentLineNumber());
            pHandlerToCall = getHandler(UNKNOWN);
          }

        break;

      case ReportTarget:
      case Method:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case Problem:
        pHandlerToCall = getHandler(mCurrentElement.second);
        static_cast< ParameterGroupHandler * >(pHandlerToCall)->setDerivedElement(pszName, mpData->pCurrentTask->getProblem());
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
Beispiel #4
0
int DummySpdyConnStream::eventLoop()
{
    int lenInBuff = 0;
    int length;

    while( m_running )
    {
        if(m_InputBuff.empty())
        {
            length = m_Datalen - lenInBuff;
            if(length == 0)
            {
                m_running = 0;
                continue;
            }
            if(length >80)
                length = 80;
            m_InputBuff.append(m_pDatabuff + lenInBuff, length);
            lenInBuff += length;

        }
        if ( isWantRead() && !m_InputBuff.empty())
        {
            getHandler()->onReadEx();
        }
        if ( isWantWrite() )
            getHandler()->onWriteEx();
        
    }
    return 0;    
}
int SpdyStream::onInitConnected()
{
    getHandler()->onInitConnected();
    if (isWantRead())
        getHandler()->onReadEx();
    if (isWantWrite())
        getHandler()->onWriteEx();
    return 0;
}
int SpdyStream::onInitConnected()
{
    getHandler()->onInitConnected();
    if (isWantRead())
        getHandler()->onReadEx();
    if (isWantWrite())
        if (next() == NULL)
            m_pSpdyConn->add2PriorityQue(this);
    return 0;
}
Beispiel #7
0
bool
EventQueue::dispatchEvent(const Event& event)
{
    void* target   = event.getTarget();
    IEventJob* job = getHandler(event.getType(), target);
    if (job == NULL) {
        job = getHandler(Event::kUnknown, target);
    }
    if (job != NULL) {
        job->run(event);
        return true;
    }
    return false;
}
Beispiel #8
0
void MySAX2Handler::inTrackPoint::startElement(const   XMLCh* const    uri,
	const   XMLCh* const    localname,
	const   XMLCh* const    qname,
	const   Attributes&     attrs)
{
    char* message = XMLString::transcode(localname);
    if(!strcmp(message, "time")) {
	setState(new inTrackPointTime(getHandler(), this, mTrack,  mPoint));
    } else if(!strcmp(message, "ele")) {
	setState(new inTrackPointEle(getHandler(), this, mTrack,  mPoint));
    } else {
	std::cout << "Unknown tag:"<< message << ":" << ": in track point"<< std::endl;
    }
    XMLString::release(&message);
}
void SpdyStream::continueRead()
{
    LS_DBG_L(this, "SpdyStream::continueRead()");
    setFlag(HIO_FLAG_WANT_READ, 1);
    if (m_bufIn.size() > 0)
        getHandler()->onReadEx();
}
Beispiel #10
0
sp<EConnectFuture> EProxyConnector::connect0(EInetSocketAddress* remoteAddress,
		EInetSocketAddress* localAddress,
		EIoSessionInitializer* sessionInitializer) {
	if (!proxyIoSession->isReconnectionNeeded()) {
		// First connection
		EIoHandler* handler = getHandler();
		if (!(instanceof<EAbstractProxyIoHandler>(handler))) {
			throw EIllegalArgumentException(__FILE__, __LINE__, "IoHandler must be an instance of AbstractProxyIoHandler");
		}

		connector->setHandler(handler);
		future = new EDefaultConnectFuture();
	}

	sp<EConnectFuture> conFuture = connector->connect(proxyIoSession->getProxyAddress(), new EProxyIoSessionInitializer(
			sessionInitializer, proxyIoSession));

	// If proxy does not use reconnection like socks the connector's
	// future is returned. If we're in the middle of a reconnection
	// then we send back the connector's future which is only used
	// internally while <code>future</code> will be used to notify
	// the user of the connection state.
	sp<EProxyRequest> pr = proxyIoSession->getRequest();
	if (dynamic_pointer_cast<ESocksProxyRequest>(pr) != null || proxyIoSession->isReconnectionNeeded()) {
		return conFuture;
	}

	return future;
}
Beispiel #11
0
LRESULT CALLBACK WindowProc::wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	MSG msg { hwnd, uMsg, wParam, lParam };

	// We dispatch certain messages back to the child widget, so that their
	// potential callbacks will die along with the child when the time comes
	HWND handler = getHandler(msg);

	// Try to get the this pointer
	Widget* w = hwnd_cast<Widget*>(handler);

	if(w) {
		if(uMsg == WM_NCDESTROY) {
			w->kill();
			return returnUnknown(msg);
		}

		LRESULT res = 0;
		if(w->handleMessage(msg, res)) {
			return res;
		}
	}

	if(handler != hwnd) {
		w = hwnd_cast<Widget*>(hwnd);
	}

	// If this fails there's something wrong
	dwtassert(w, "Expected to get a pointer to a widget - something's wrong");

	if(!w) {
		return returnUnknown(msg);
	}

	return w->getDispatcher().chain(msg);
}
Beispiel #12
0
    void TcpClient::connect(const IpAddress& address, NetPort port, const Duration& timeout, const Duration& pause)
    {
        Expect(address.isValid(), Throw(InvalidParameter, "Invalid IpAddress"));
        Expect(port != NetPort_Any, Throw(InvalidParameter, "Invalid NetPort"));

        int ret;
        Clock clock;

        Socket::create(address.getProtocol());

        prv::SockAddrBuffer buffer(address, port);

        clock.start();

        do
        {
            ret = ::connect(getHandler(), buffer.getSockAddr(), buffer.getLength());

            if(ret != 0)
            {
                std::this_thread::sleep_for(std::chrono::milliseconds(static_cast<long long>(pause.asMilliseconds())));
            }
        }while(ret != 0 && clock.getElapsedTime() < timeout);

        Expect(ret == 0, Throw(InternalError, "Failed to connect to the remote host"));
    }
Beispiel #13
0
void MenuSystem::doWork(void)
{
  button_t button = m_readButton();
  unsigned long elapsed = getElapsedDuration();
  if (button == BUTTON_NONE)
  {
    unsigned long dur = getTimeoutDuration();
    if (dur != 0 && dur < elapsed)
      button = BUTTON_TIMEOUT;
  }

  // Debounce: wait for last button to be released
  if (elapsed < 250)
    return;
  if (button != BUTTON_TIMEOUT)
    m_lastButton = button;
  if (button == BUTTON_NONE)
    return;

  //Serial.print("New button: ");
  //Serial.println(button, DEC);

  m_lastActivity = millis();
  
  state_t newState = ST_AUTO;
  handler_t handler = getHandler();
  if (handler != NULL)
    newState = handler(button);
  if (newState == ST_AUTO)
    newState = findTransition(button);

  setState(newState);
}
        OCEntityHandlerResult RCSResourceObject::handleRequestSet(
                std::shared_ptr< OC::OCResourceRequest > request)
        {
            assert(request != nullptr);

            auto attrs = getAttributesFromOCRequest(request);
            auto response = invokeHandler(attrs, request, m_setRequestHandler);
            auto requestHandler = response.getHandler();

            assert(requestHandler != nullptr);

            AttrKeyValuePairs replaced = requestHandler->applyAcceptanceMethod(
                    response.getAcceptanceMethod(), *this, attrs);

            for (const auto& attrKeyValPair : replaced)
            {
                std::lock_guard<std::mutex> lock(m_mutexKeyAttributeUpdate);

                auto keyAttrListener = m_keyAttributesUpdatedListeners.find(attrKeyValPair.first);
                if(keyAttrListener != m_keyAttributesUpdatedListeners.end())
                {
                    keyAttrListener-> second(attrKeyValPair.second, attrs[attrKeyValPair.first]);
                }
            }

            autoNotify(!replaced.empty(), m_autoNotifyPolicy);
            return sendResponse(*this, request, response);
        }
Beispiel #15
0
int DummySpdyConnStream::onInitConnected()
{
    getHandler()->onInitConnected();
    m_running = 1;
    eventLoop();
    return 0;
}
Beispiel #16
0
void MySAX2Handler::inTrackSegment::startElement(const   XMLCh* const    uri,
	const   XMLCh* const    localname,
	const   XMLCh* const    qname,
	const   Attributes&     attrs)
{
    char* message = XMLString::transcode(localname);
    if(!strcmp(message, "trkpt")) {
	XMLCh* latStr = XMLString::transcode("lat");
	XMLCh* lonStr = XMLString::transcode("lon");
	const   XMLCh* xmlLat = attrs.getValue(latStr);
	const   XMLCh* xmlLon = attrs.getValue(lonStr);
	XMLString::release(&latStr);
	XMLString::release(&lonStr);
	if(xmlLat && xmlLon) {
	    char* slat = XMLString::transcode(xmlLat);
	    char* slon = XMLString::transcode(xmlLon);
	    double lat = strtod(slat, (char **)NULL);
	    double lon = strtod(slon, (char **)NULL);
	    Track::TrackPoint *tp = new Track::TrackPoint(lat, lon);
	    mSegment->addPoint(tp);
	    //std::cout << "New point: (" << lat << ", " << lon << ") : " << *tp << std::endl;
	    setState(new inTrackPoint(getHandler(), this, mTrack,  *tp));
	    XMLString::release(&slat);
	    XMLString::release(&slon);
	} else {
	    std::cout << "Can't find lat " << xmlLat << " and " << xmlLon
		<< std::endl;
	}
    } else {
	std::cout << "Unknown tag:"<< message << ":" << ": in track segment"<< std::endl;
    }
    XMLString::release(&message);
}
Beispiel #17
0
void
V3Handler::setLastHandler() {
   assert (getHandlerCount()); if (_curHandlerId == _lastHandlerId) return;
   const uint32_t curHandlerId = _curHandlerId; assert (getHandler(curHandlerId));
   V3UI32Vec curRefIdVec = _curRefIdVec; assert (curRefIdVec.size());
   _curHandlerId = _lastHandlerId; _curRefIdVec = _lastRefIdVec;
   _lastHandlerId = curHandlerId; _lastRefIdVec = curRefIdVec;
}
Beispiel #18
0
/**
 * inTrack Stuff
 */
void MySAX2Handler::inTrack::startElement(const   XMLCh* const    uri,
	const   XMLCh* const    localname,
	const   XMLCh* const    qname,
	const   Attributes&     attrs)
{
    char* message = XMLString::transcode(localname);
    char* qn = XMLString::transcode(qname);
    if(!strcmp(message, "name")) {
	setState(new inTrackName(getHandler(), this, mTrack));
    } else if(!strcmp(message, "trkseg")) {
	setState(new inTrackSegment(getHandler(), this, mTrack));
    } else {
	std::cout << "Unknown tag:"<< message << ":" << qn <<": in track"<< std::endl;
    }
    XMLString::release(&message);
    XMLString::release(&qn);
}
Beispiel #19
0
		void handle(const char* message, lua_State *state)
		{
			function_type handler = getHandler(state);
			if (handler)
			{
				handler(0, message);
			}
		}
Beispiel #20
0
		void handle(int status_code, lua_State *state)
		{
			function_type handler = getHandler(state);
			if (handler)
			{
				handler(status_code, get_error_message(state));
			}
		}
Beispiel #21
0
// virtual
CXMLHandler * ReactionGlyphHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;

  switch (mCurrentElement.first)
    {
      case ReactionGlyph:
      {
        //workload
        const char * key;
        const char * name;
        const char * reaction;
        key = mpParser->getAttributeValue("key", papszAttrs);
        name = mpParser->getAttributeValue("name", papszAttrs);
        reaction = mpParser->getAttributeValue("reaction", papszAttrs, false);

        mpData->pReactionGlyph = new CLReactionGlyph(name);
        const char * objectRole = mpParser->getAttributeValue("objectRole", papszAttrs, false);

        if (objectRole != NULL && objectRole[0] != 0)
          {
            mpData->pReactionGlyph->setObjectRole(objectRole);
          }

        if (reaction && reaction[0])
          {
            CReaction * pReaction = dynamic_cast< CReaction * >(mpData->mKeyMap.get(reaction));

            if (!pReaction)
              {
                CCopasiMessage(CCopasiMessage::WARNING, MCXML + 19, "ReactionGlyph" , key);
              }
            else
              {
                mpData->pReactionGlyph->setModelObjectKey(pReaction->getKey());
              }
          }

        mpData->pCurrentLayout->addReactionGlyph(mpData->pReactionGlyph);
        addFix(key, mpData->pReactionGlyph);
      }
      break;

      case BoundingBox:
      case Curve:
      case ListOfMetaboliteReferenceGlyphs:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
int SpdyStream::close()
{
    if (getState() == HIOS_DISCONNECTED)
        return 0;
    if (getHandler() && !isReadyToRelease())
        getHandler()->onCloseEx();
    shutdown();
    setFlag(HIO_FLAG_WANT_WRITE, 1);
    setState(HIOS_DISCONNECTED);
    m_pSpdyConn->continueWrite();
    //if (getHandler())
    //{
    //    getHandler()->recycle();
    //    setHandler( NULL );
    //}
    m_pSpdyConn->recycleStream(m_uiStreamID);
    return 0;
}
Beispiel #23
0
void MethodRegister::onCall(const sg::rpc::Uri& target)
{
    if (!getFrom().has_service_type() || getFrom().service_type().empty())
        THROW_APP_EXCEPTION(sg::rpc::EC_RPC_INVALID_PARAMS, "missing service type field!");

    base::net::SockAddr sockaddr(getHandler()->addr().getAddr().c_str(), getRequestData().routing_port());
    common::ServerID svc_id(getFrom());
    ConfigService::instance()->getServersList().addServer(
            svc_id,
            sockaddr,
            boost::static_pointer_cast<ServerConnectionHandler>(getHandler()),
            getRequestData().info(),
            getRequestData().overwrite_if_exist());

    rpc::RegisterResponse resp;
    resp.set_service_number(svc_id.svc_num);
    reply(target, resp);
}
Beispiel #24
0
// virtual
CXMLHandler * PlotItemHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;
  std::string name;
  std::string sType;
  CCopasiParameterGroup * pGroup = NULL;

  switch (mCurrentElement.first)
    {
      case PlotItem:
        // create a new CPlotSpecification element depending on the type
        name = mpParser->getAttributeValue("name", papszAttrs);
        sType = mpParser->getAttributeValue("type", papszAttrs);
        mpData->pCurrentPlotItem =
          mpData->pCurrentPlot->createItem(name, toEnum(sType.c_str(), CPlotItem::XMLType, CPlotItem::unset));

        break;

      case ParameterGroup:
        pHandlerToCall = getHandler(mCurrentElement.second);
        pGroup = dynamic_cast< CCopasiParameterGroup * >(mpData->pCurrentPlot->getParameter(pszName));

        if (pGroup != NULL)
          static_cast< ParameterGroupHandler * >(pHandlerToCall)->setDerivedElement(pszName, pGroup);

        break;

      case Parameter:
      case ListOfChannels:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}
Beispiel #25
0
    std::size_t TcpClient::receive(void* data, std::size_t length)
    {
        Expect(data && length, Throw(InvalidParameter, "Invalid buffer"));
        Expect(isConnected(), Throw(LogicError, "TcpClient is not connected"));

        int received = ::recv(getHandler(), reinterpret_cast<char*>(data), length, 0);

        Expect(received >= 0, Throw(InternalError, "Failed to receive data from the remote host"));

        return received;
    }
Beispiel #26
0
    std::size_t TcpClient::send(const void* data, std::size_t length)
    {
        Expect(data && length, Throw(InvalidParameter, "Invalid buffer"));
        Expect(isConnected(), Throw(LogicError, "TcpClient is not connected"));

        int sent = ::send(getHandler(), reinterpret_cast<const char*>(data), length, 0);

        Expect(sent >= 0, Throw(InternalError, "Failed to send data to the remote host"));

        return sent;
    }
Beispiel #27
0
// static
void LLTranslate::verifyKey(
	KeyVerificationReceiverPtr& receiver,
	const std::string& key)
{
	std::string url;
	const LLTranslationAPIHandler& handler = getHandler(receiver->getService());
	handler.getKeyVerificationURL(url, key);

	LL_DEBUGS("Translate") << "Sending key verification request: " << url << LL_ENDL;
	sendRequest(url, receiver);
}
Beispiel #28
0
void CCBProxy::handleEvent(CCControl *n, const int handler, bool multiTouches, CCControlEvent e){
#if COCOS2D_VERSION > 0x00020100
	n->addHandleOfControlEvent(handler, e);
#else
	LuaEventHandler *h = getHandler(handler);
	if(!h){
		h = addHandler(handler, multiTouches)
			->setTypename("CCControlButton");
	}
	n->addTargetWithActionForControlEvents(h, cccontrol_selector(LuaEventHandler::controlAction), e);
#endif
}
Beispiel #29
0
// static
const LLTranslationAPIHandler& LLTranslate::getPreferredHandler()
{
	EService service = SERVICE_BING;

	std::string service_str = gSavedSettings.getString("TranslationService");
	if (service_str == "google")
	{
		service = SERVICE_GOOGLE;
	}

	return getHandler(service);
}
void MethodUpdateStatus::onCall(const sg::rpc::Uri& target)
{
    if (!getFrom().has_service_number())
        THROW_APP_EXCEPTION(sg::rpc::EC_RPC_INVALID_PARAMS, "service id is empty.");

    ConfigService::instance()->getServersList().updateServerStatus(
            common::ServerID(getFrom()),
            boost::static_pointer_cast<ServerConnectionHandler>(getHandler()),
            getRequestData().status());

    reply(target);
}