Beispiel #1
0
static void HHVM_METHOD(ResourceBundle, __construct, const Variant& locale,
                                                     const Variant& bundleName,
                                                     bool fallback) {
  const char *bundle = bundleName.isNull() ? nullptr :
                       bundleName.toString().c_str();
  auto loc = Locale::createFromName(localeOrDefault(locale.toString()).c_str());
  auto data = Native::data<ResourceBundle>(this_.get());
  UErrorCode error = U_ZERO_ERROR;
  auto rsrc = new icu::ResourceBundle(bundle, loc, error);
  if (U_FAILURE(error)) {
    s_intl_error->setError(error, "resourcebundle_ctor: "
                                  "Cannot load libICU resource bundle");
    throw data->getException("%s", s_intl_error->getErrorMessage().c_str());
  }
  if (!fallback &&
      ((error == U_USING_FALLBACK_WARNING) ||
       (error == U_USING_DEFAULT_WARNING))) {
    UErrorCode dummy = U_ZERO_ERROR;
    s_intl_error->setError(error,
      "resourcebundle_ctor: Cannot load libICU resource "
      "'%s' without fallback from %s to %s",
      bundle ? bundle : "(default data)", loc.getName(),
      rsrc->getLocale(ULOC_ACTUAL_LOCALE, dummy).getName());
    delete rsrc;
    throw data->getException("%s", s_intl_error->getErrorMessage().c_str());
  }
  data->setResource(rsrc);
}
/**
 * This sets up the 'Gateway' java class for execution of
 * scripts.   The class's constructor takes a jlong.  This java long
 * is used to store the pointer to 'this'.  When ScriptRunner makes
 * native calls, it passes that jlong back, so that it can call the
 * methods of this C++ class.  
 */  
bool JavaBinderyImpl::setupGateway()
{
    String className = "org/inkscape/cmn/Gateway";
    if (!registerNatives(className, gatewayMethods))
        {
        return false;
        }
    jclass cls = env->FindClass(className.c_str());
    if (!cls)
        {
        err("setupGateway: cannot find class '%s' : %s",
		         className.c_str(), getException().c_str());
        return false;
		}
	jmethodID mid = env->GetMethodID(cls, "<init>", "(J)V");
	if (!mid)
        {
        err("setupGateway: cannot find constructor for '%s' : %s",
		          className.c_str(), getException().c_str());
        return false;
		}
    gatewayObj = env->NewObject(cls, mid, ((jlong)this));
    if (!gatewayObj)
        {
        err("setupGateway: cannot construct '%s' : %s",
		         className.c_str(), getException().c_str());
        return false;
		}

	msg("Gateway ready");
    return true;
}
Beispiel #3
0
void SqliteConnection::copy_to(const SqliteConnectionPtr& pDest) {
    sqlite3_backup* backup =
        sqlite3_backup_init(pDest->conn(), "main", pConn_, "main");

    int rc = sqlite3_backup_step(backup, -1);
    if (rc != SQLITE_DONE) {
        stop("Failed to copy all data:\n%s", getException());
    }
    rc = sqlite3_backup_finish(backup);
    if (rc != SQLITE_OK) {
        stop("Could not finish copy:\n%s", getException());
    }
}
void c_GenVectorWaitHandle::onUnblocked() {
  for (; m_iterPos < m_deps->size(); ++m_iterPos) {

    Cell* current = tvAssertCell(m_deps->at(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(dynamic_cast<c_WaitHandle*>(current->m_data.pobj));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      cellSet(child->getResult(), *current);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(dynamic_cast<c_WaitableWaitHandle*>(child));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  if (m_exception.isNull()) {
    setResult(make_tv<KindOfObject>(m_deps.get()));
    m_deps = nullptr;
  } else {
    setException(m_exception.get());
    m_exception = nullptr;
    m_deps = nullptr;
  }
}
void FlowControlFilter::onWindowUpdate(StreamID stream, uint32_t amount) {
  if (!stream) {
    bool success = sendWindow_.free(amount);
    VLOG(4) << "Remote side ack'd " << amount << " bytes, sendWindow=" <<
      sendWindow_.getSize();
    if (!success) {
      LOG(WARNING) << "Remote side sent connection-level WINDOW_UPDATE "
                   << "that could not be applied. Aborting session.";
      // If something went wrong applying the flow control change, abort
      // the entire session.
      error_ = true;
      HTTPException ex = getException(
        folly::to<std::string>(
          "Failed to update send window, outstanding=",
          sendWindow_.getOutstanding(), ", amount=", amount));
      callback_->onError(stream, ex, false);
    }
    if (sendsBlocked_ && sendWindow_.getNonNegativeSize()) {
      VLOG(4) << "Send window opened";
      sendsBlocked_ = false;
      notify_.onConnectionSendWindowOpen();
    }
    // Don't forward.
  } else {
    callback_->onWindowUpdate(stream, amount);
  }
}
Beispiel #6
0
Object c_GenMapWaitHandle::ti_create(const Variant& dependencies) {
  if (UNLIKELY(!dependencies.isObject() ||
      dependencies.getObjectData()->getCollectionType() !=
        Collection::MapType)) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Expected dependencies to be an instance of Map"));
    throw e;
  }
  assert(dependencies.getObjectData()->instanceof(c_Map::classof()));
  auto deps = p_Map::attach(c_Map::Clone(dependencies.getObjectData()));
  for (ssize_t iter_pos = deps->iter_begin();
       deps->iter_valid(iter_pos);
       iter_pos = deps->iter_next(iter_pos)) {

    auto* current = tvAssertCell(deps->iter_value(iter_pos));
    if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
      Object e(SystemLib::AllocInvalidArgumentExceptionObject(
        "Expected dependencies to be a map of WaitHandle instances"));
      throw e;
    }
  }

  Object exception;
  for (ssize_t iter_pos = deps->iter_begin();
       deps->iter_valid(iter_pos);
       iter_pos = deps->iter_next(iter_pos)) {

    auto* current = tvAssertCell(deps->iter_value(iter_pos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto k = deps->iter_key(iter_pos);
      deps->set(k.asCell(), &child->getResult());
    } else if (child->isFailed()) {
      putException(exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      p_GenMapWaitHandle my_wh = NEWOBJ(c_GenMapWaitHandle)();
      my_wh->initialize(exception, deps.get(), iter_pos, child_wh);

      AsioSession* session = AsioSession::Get();
      if (UNLIKELY(session->hasOnGenMapCreateCallback())) {
        session->onGenMapCreate(my_wh.get(), dependencies);
      }

      return my_wh;
    }
  }

  if (exception.isNull()) {
    return Object::attach(c_StaticWaitHandle::CreateSucceeded(
      make_tv<KindOfObject>(deps.detach())));
  } else {
    return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
  }
}
Beispiel #7
0
void KManualProxyDlg::changePressed()
{
  QString result;
  if( getException( result, i18n("Change Exception"), 
                    mDlg->lbExceptions->currentText() ) &&
      !handleDuplicate( result ) )
      mDlg->lbExceptions->changeItem( result, mDlg->lbExceptions->currentItem() );
}
Object c_GenArrayWaitHandle::ti_create(const char* cls, CArrRef dependencies) {
    Array deps = dependencies->copy();
    for (ssize_t iter_pos = deps->iter_begin();
            iter_pos != ArrayData::invalid_index;
            iter_pos = deps->iter_advance(iter_pos)) {

        TypedValue* current = deps->nvGetValueRef(iter_pos);
        if (UNLIKELY(current->m_type == KindOfRef)) {
            tvUnbox(current);
        }

        if (!c_WaitHandle::fromTypedValue(current) &&
                !IS_NULL_TYPE(current->m_type)) {
            Object e(SystemLib::AllocInvalidArgumentExceptionObject(
                         "Expected dependencies to be an array of WaitHandle instances"));
            throw e;
        }
    }

    Object exception;
    for (ssize_t iter_pos = deps->iter_begin();
            iter_pos != ArrayData::invalid_index;
            iter_pos = deps->iter_advance(iter_pos)) {

        TypedValue* current = deps->nvGetValueRef(iter_pos);
        if (IS_NULL_TYPE(current->m_type)) {
            // {uninit,null} yields null
            tvWriteNull(current);
            continue;
        }

        assert(current->m_type == KindOfObject);
        assert(dynamic_cast<c_WaitHandle*>(current->m_data.pobj));
        auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

        if (child->isSucceeded()) {
            tvSetIgnoreRef(child->getResult(), current);
        } else if (child->isFailed()) {
            putException(exception, child->getException());
        } else {
            assert(dynamic_cast<c_WaitableWaitHandle*>(child));
            auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

            c_GenArrayWaitHandle* my_wh = NEWOBJ(c_GenArrayWaitHandle)();
            my_wh->initialize(exception, deps, iter_pos, child_wh);
            return my_wh;
        }
    }

    if (exception.isNull()) {
        TypedValue tv;
        tv.m_type = KindOfArray;
        tv.m_data.parr = deps.get();
        return c_StaticResultWaitHandle::Create(&tv);
    } else {
        return c_StaticExceptionWaitHandle::Create(exception.get());
    }
}
/**
 * Used to register an array of native methods for a named class
 * 
 * @param className the full name of the java class
 * @param the method array
 * @return true if successful, else false     
 */ 
bool JavaBinderyImpl::registerNatives(const String &className,
                           const JNINativeMethod *methods)
{
    jclass cls = env->FindClass(className.c_str());
    if (!cls)
        {
        err("Could not find class '%s'", className.c_str());
        return false;
        }
    //msg("registerNatives: class '%s' found", className.c_str());
    
    /**
     * hack for JDK bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6493522
     */
	jmethodID mid = env->GetMethodID(env->GetObjectClass(cls), "getConstructors",
	          "()[Ljava/lang/reflect/Constructor;");
	if (!mid)
	    {
	    err("Could not get reflect mid for 'getConstructors' : %s",
             getException().c_str());
		return false;
		}
	jobject res = env->CallObjectMethod(cls, mid);
	if (!res)
	    {
	    err("Could not get constructors : %s", getException().c_str());
		return false;
		}
	/**
	 * end hack
	 */	 	
    jint nrMethods = 0;
    for (const JNINativeMethod *m = methods ; m->name ; m++)
        nrMethods++;
    jint ret = env->RegisterNatives(cls, methods, nrMethods);
    if (ret < 0)
        {
        err("Could not register %d native methods for '%s' : %s",
		    nrMethods, className.c_str(), getException().c_str());
        return false;
        }
    return true;
}
Object c_GenVectorWaitHandle::ti_create(const Variant& dependencies) {
  if (UNLIKELY(!dependencies.isObject() ||
      dependencies.getObjectData()->getCollectionType() !=
        Collection::VectorType)) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Expected dependencies to be an instance of Vector"));
    throw e;
  }
  assert(dependencies.getObjectData()->instanceof(c_Vector::classof()));
  auto deps = SmartObject<c_Vector>::attach(
    c_Vector::Clone(dependencies.getObjectData()));
  for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
    Cell* current = deps->at(iter_pos);

    if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
      Object e(SystemLib::AllocInvalidArgumentExceptionObject(
        "Expected dependencies to be a vector of WaitHandle instances"));
      throw e;
    }
  }

  Object exception;
  for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {

    auto current = tvAssertCell(deps->at(iter_pos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto result = child->getResult();
      deps->set(iter_pos, &result);
    } else if (child->isFailed()) {
      putException(exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      SmartObject<c_GenVectorWaitHandle> my_wh(newobj<c_GenVectorWaitHandle>());
      my_wh->initialize(exception, deps.get(), iter_pos, child_wh);
      AsioSession* session = AsioSession::Get();
      if (UNLIKELY(session->hasOnGenVectorCreateCallback())) {
        session->onGenVectorCreate(my_wh.get(), dependencies);
      }
      return my_wh;
    }
  }

  if (exception.isNull()) {
    return Object::attach(c_StaticWaitHandle::CreateSucceeded(
      make_tv<KindOfObject>(deps.detach())));
  } else {
    return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
  }
}
Beispiel #11
0
Variant c_WaitHandle::result() {
  assert(isFinished());

  if (LIKELY(isSucceeded())) {
    // succeeded? return result
    return cellAsCVarRef(getResult());
  } else {
    // failed? throw exception
    throw Object{getException()};
  }
}
Beispiel #12
0
SqliteConnection::SqliteConnection(const std::string& path, const bool allow_ext, const int flags, const std::string& vfs)
    : pConn_(NULL) {

    // Get the underlying database connection
    int rc = sqlite3_open_v2(path.c_str(), &pConn_, flags, vfs.size() ? vfs.c_str() : NULL);
    if (rc != SQLITE_OK) {
        stop("Could not connect to database:\n%s", getException());
    }
    if (allow_ext) {
        sqlite3_enable_load_extension(pConn_, 1);
    }
}
Object c_GenVectorWaitHandle::ti_create(CVarRef dependencies) {
  if (UNLIKELY(!dependencies.instanceof(c_Vector::s_cls))) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Expected dependencies to be an instance of Vector"));
    throw e;
  }
  assert(dynamic_cast<c_Vector*>(dependencies.getObjectData()));
  p_Vector deps = static_cast<c_Vector*>(dependencies.getObjectData())->clone();
  for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
    Cell* current = deps->at(iter_pos);

    if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
      Object e(SystemLib::AllocInvalidArgumentExceptionObject(
        "Expected dependencies to be a vector of WaitHandle instances"));
      throw e;
    }
  }

  Object exception;
  for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {

    Cell* current = tvAssertCell(deps->at(iter_pos));
    assert(current->m_type == KindOfObject);
    assert(dynamic_cast<c_WaitHandle*>(current->m_data.pobj));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      cellSet(child->getResult(), *current);
    } else if (child->isFailed()) {
      putException(exception, child->getException());
    } else {
      assert(dynamic_cast<c_WaitableWaitHandle*>(child));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      p_GenVectorWaitHandle my_wh = NEWOBJ(c_GenVectorWaitHandle)();
      my_wh->initialize(exception, deps.get(), iter_pos, child_wh);
      AsioSession* session = AsioSession::Get();
      if (UNLIKELY(session->hasOnGenVectorCreateCallback())) {
        session->onGenVectorCreate(my_wh.get(), dependencies);
      }
      return my_wh;
    }
  }

  if (exception.isNull()) {
    return c_StaticResultWaitHandle::Create(make_tv<KindOfObject>(deps.get()));
  } else {
    return c_StaticExceptionWaitHandle::Create(exception.get());
  }
}
void c_AsyncFunctionWaitHandle::resume() {
  auto const child = m_children[0].getChild();
  assert(getState() == STATE_READY);
  assert(child->isFinished());
  setState(STATE_RUNNING);

  if (LIKELY(child->isSucceeded())) {
    // child succeeded, pass the result to the async function
    g_context->resumeAsyncFunc(resumable(), child, child->getResult());
  } else {
    // child failed, raise the exception inside the async function
    g_context->resumeAsyncFuncThrow(resumable(), child,
                                    child->getException());
  }
}
Beispiel #15
0
void c_GenMapWaitHandle::onUnblocked() {
  assert(getState() == STATE_BLOCKED);

  for (;
       m_deps->iter_valid(m_iterPos);
       m_iterPos = m_deps->iter_next(m_iterPos)) {

    auto* current = tvAssertCell(m_deps->iter_value(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto k = m_deps->iter_key(m_iterPos);
      m_deps->set(k.asCell(), &child->getResult());
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        if (isInContext()) {
          child_wh->enterContext(getContextIdx());
        }
        detectCycle(child_wh);
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  auto const parentChain = getFirstParent();
  if (m_exception.isNull()) {
    setState(STATE_SUCCEEDED);
    tvWriteObject(m_deps.get(), &m_resultOrException);
  } else {
    setState(STATE_FAILED);
    tvWriteObject(m_exception.get(), &m_resultOrException);
    m_exception = nullptr;
  }

  m_deps = nullptr;
  UnblockChain(parentChain);
  decRefObj(this);
}
Beispiel #16
0
Variant c_WaitHandle::t_join() {
  if (!isFinished()) {
    // run the full blown machinery
    assert(instanceof(c_WaitableWaitHandle::classof()));
    static_cast<c_WaitableWaitHandle*>(this)->join();
  }
  assert(isFinished());

  if (LIKELY(isSucceeded())) {
    // succeeded? return result
    return cellAsCVarRef(getResult());
  } else {
    // failed? throw exception
    throw Object{getException()};
  }
}
void c_GenArrayWaitHandle::onUnblocked() {
  for (;
       m_iterPos != ArrayData::invalid_index;
       m_iterPos = m_deps->iter_advance(m_iterPos)) {

    TypedValue* current = m_deps->nvGetValueRef(m_iterPos);
    if (IS_NULL_TYPE(current->m_type)) {
      // {uninit,null} yields null
      tvWriteNull(current);
      continue;
    }

    assert(current->m_type == KindOfObject);
    assert(dynamic_cast<c_WaitHandle*>(current->m_data.pobj));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      tvSetIgnoreRef(child->getResult(), current);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(dynamic_cast<c_WaitableWaitHandle*>(child));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  if (m_exception.isNull()) {
    TypedValue result;
    result.m_type = KindOfArray;
    result.m_data.parr = m_deps.get();
    setResult(&result);
    m_deps = nullptr;
  } else {
    setException(m_exception.get());
    m_exception = nullptr;
    m_deps = nullptr;
  }
}
Beispiel #18
0
Variant c_WaitHandle::t_join() {
  if (!isFinished()) {
    // run the full blown machinery
    assert(dynamic_cast<c_WaitableWaitHandle*>(this));
    static_cast<c_WaitableWaitHandle*>(this)->join();
  }

  assert(isFinished());

  if (LIKELY(isSucceeded())) {
    // succeeded? return result
    return tvAsCVarRef(getResult());
  } else {
    // failed? throw exception
    Object e(getException());
    throw e;
  }
}
void c_GenVectorWaitHandle::onUnblocked() {
  assert(getState() == STATE_BLOCKED);

  for (; m_iterPos < m_deps->size(); ++m_iterPos) {

    Cell* current = tvAssertCell(m_deps->at(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto result = child->getResult();
      m_deps->set(m_iterPos, &result);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        detectCycle(child_wh);
        child_wh->getParentChain()
          .addParent(m_blockable, AsioBlockable::Kind::GenVectorWaitHandle);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  auto parentChain = getParentChain();
  if (m_exception.isNull()) {
    setState(STATE_SUCCEEDED);
    tvWriteObject(m_deps.get(), &m_resultOrException);
  } else {
    setState(STATE_FAILED);
    tvWriteObject(m_exception.get(), &m_resultOrException);
    m_exception = nullptr;
  }

  m_deps = nullptr;
  parentChain.unblock();
  decRefObj(this);
}
void c_GenVectorWaitHandle::onUnblocked() {
  assert(getState() == STATE_BLOCKED);

  for (; m_iterPos < m_deps->size(); ++m_iterPos) {

    Cell* current = tvAssertCell(m_deps->at(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      cellSet(child->getResult(), *current);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        if (isInContext()) {
          child_wh->enterContext(getContextIdx());
        }
        detectCycle(child_wh);
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  if (m_exception.isNull()) {
    setState(STATE_SUCCEEDED);
    tvWriteObject(m_deps.get(), &m_resultOrException);
  } else {
    setState(STATE_FAILED);
    tvWriteObject(m_exception.get(), &m_resultOrException);
    m_exception = nullptr;
  }

  m_deps = nullptr;
  done();
}
void FlowControlFilter::onBody(StreamID stream,
                               std::unique_ptr<folly::IOBuf> chain,
                               uint16_t padding) {
  uint64_t amount = chain->computeChainDataLength();
  if (!recvWindow_.reserve(amount + padding)) {
    error_ = true;
    HTTPException ex = getException(
      folly::to<std::string>(
        "Failed to reserve receive window, window size=",
        recvWindow_.getSize(), ", amount=", amount));
    callback_->onError(0, ex, false);
  } else {
    if (VLOG_IS_ON(4) && recvWindow_.getSize() == 0) {
      VLOG(4) << "recvWindow full";
    }
    toAck_ += padding;
    CHECK(recvWindow_.free(padding));
    callback_->onBody(stream, std::move(chain), padding);
  }
}
void c_AsyncFunctionWaitHandle::resume() {
  // may happen if scheduled in multiple contexts
  if (getState() != STATE_SCHEDULED) {
    decRefObj(this);
    return;
  }

  auto const child = m_children[0].getChild();
  assert(getState() == STATE_SCHEDULED);
  assert(child->isFinished());
  setState(STATE_RUNNING);

  if (LIKELY(child->isSucceeded())) {
    // child succeeded, pass the result to the async function
    g_context->resumeAsyncFunc(resumable(), child, child->getResult());
  } else {
    // child failed, raise the exception inside the async function
    g_context->resumeAsyncFuncThrow(resumable(), child,
                                    child->getException());
  }
}
Beispiel #23
0
void c_GenMapWaitHandle::onUnblocked() {
  for (;
       m_deps->iter_valid(m_iterPos);
       m_iterPos = m_deps->iter_next(m_iterPos)) {

    Cell* current = tvAssertCell(m_deps->iter_value(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      cellSet(child->getResult(), *current);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        if (isInContext()) {
          child_wh->enterContext(getContextIdx());
        }
        detectCycle(child_wh);
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  if (m_exception.isNull()) {
    setResult(make_tv<KindOfObject>(m_deps.get()));
    m_deps = nullptr;
  } else {
    setException(m_exception.get());
    m_exception = nullptr;
    m_deps = nullptr;
  }
}
Beispiel #24
0
			/**
			 * read out the data in the decompressed block
			 *
			 * @param ldata buffer for storing the decompressed block
			 * @param n size of buffer ldata in bytes
			 * @return the number of uncompressed bytes in the buffer
			 **/
			uint64_t read(char * const ldata, uint64_t const n)
			{
				state = bgzfinflateblockstate_idle;
				
				if ( n < getBgzfMaxBlockSize() )
				{
					::libmaus2::exception::LibMausException se;
					se.getStream() << "BgzfInflate::decompressBlock(): provided buffer is too small: " << n << " < " << getBgzfMaxBlockSize();
					se.finish(false);
					throw se;				
				}
				
				if ( failed() )
					throw getException();

				uint64_t const ndata = blockinfo.uncompressed;
					
				std::copy ( data.begin(), data.begin() + ndata, reinterpret_cast<uint8_t *>(ldata) );
				
				blockinfo = ::libmaus2::lz::BgzfInflateInfo(0,0,true);
				
				return ndata;
			}
Beispiel #25
0
Object c_WaitHandle::t_getexceptioniffailed() {
  return isFailed() ? getException() : nullptr;
}
Beispiel #26
0
void KManualProxyDlg::newPressed()
{
  QString result;
  if( getException(result, i18n("New Exception")) && !handleDuplicate(result) )
    mDlg->lbExceptions->insertItem( result );
}
Beispiel #27
0
Object c_GenMapWaitHandle::ti_create(const Variant& dependencies) {
  ObjectData* obj;
  if (UNLIKELY(!dependencies.isObject() ||
      !(obj = dependencies.getObjectData())->isCollection() ||
      obj->collectionType() != CollectionType::Map)) {
    SystemLib::throwInvalidArgumentExceptionObject(
      "Expected dependencies to be an instance of Map");
  }
  assertx(obj->collectionType() == CollectionType::Map);
  auto deps = req::ptr<c_Map>::attach(c_Map::Clone(obj));
  auto ctx_idx = std::numeric_limits<context_idx_t>::max();
  for (ssize_t iter_pos = deps->iter_begin();
       deps->iter_valid(iter_pos);
       iter_pos = deps->iter_next(iter_pos)) {

    auto* current = tvAssertCell(deps->iter_value(iter_pos));
    auto const child = c_WaitHandle::fromCell(current);
    if (UNLIKELY(!child)) {
      SystemLib::throwInvalidArgumentExceptionObject(
        "Expected dependencies to be a map of WaitHandle instances");
    }

    if (!child->isFinished()) {
      ctx_idx = std::min(
        ctx_idx,
        static_cast<c_WaitableWaitHandle*>(child)->getContextIdx()
      );
    }
  }

  Object exception;
  for (ssize_t iter_pos = deps->iter_begin();
       deps->iter_valid(iter_pos);
       iter_pos = deps->iter_next(iter_pos)) {

    auto* current = tvAssertCell(deps->iter_value(iter_pos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto k = deps->iter_key(iter_pos);
      auto result = child->getResult();
      deps->set(k.asCell(), &result);
    } else if (child->isFailed()) {
      putException(exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      auto my_wh = req::make<c_GenMapWaitHandle>();
      my_wh->initialize(exception, deps.get(), iter_pos, ctx_idx, child_wh);

      AsioSession* session = AsioSession::Get();
      if (UNLIKELY(session->hasOnGenMapCreate())) {
        session->onGenMapCreate(my_wh.get(), dependencies);
      }

      return Object(std::move(my_wh));
    }
  }

  if (exception.isNull()) {
    return Object::attach(c_StaticWaitHandle::CreateSucceeded(
      make_tv<KindOfObject>(deps.detach())));
  } else {
    return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
  }
}
Beispiel #28
0
int main() {

	int cew_Test_Count = 0;
	 int cew_Error_Count = 0;
	


	/******************************************************************
	Empty Simple Set 
	******************************************************************/
	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSDel(10);SSDel(10);
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 15);
		 printf("There was no Exception thrown\n");
		 printf("Expected Exception was %s\n", getException(NotFoundExc));
	 }
	 CATCH {
		 if (EXnum__ != (NotFoundExc)) {
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 15);
			 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
		 }
	 }
 	 FINALLY
	 ETRY;
	

	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSDel(10);
		 if (SSSize() != 0){
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 16);
			 printf("Actual Value was %d\n", SSSize());
	       printf("Expected Value was %d\n", 0);
		 }
	 }
	 CATCH {
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 16);
		 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
	 }
	 FINALLY
	 ETRY;
	

	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSDel(10); (1/0);
		 if (SSSize() != 0){
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 17);
			 printf("Actual Value was %d\n", SSSize());
	       printf("Expected Value was %d\n", 0);
		 }
	 }
	 CATCH {
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 17);
		 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
	 }
	 FINALLY
	 ETRY;
	

	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 18);
		 printf("There was no Exception thrown\n");
		 printf("Expected Exception was %s\n", getException(FullExc));
	 }
	 CATCH {
		 if (EXnum__ != (FullExc)) {
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 18);
			 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
		 }
	 }
 	 FINALLY
	 ETRY;
	
 				/* Should Fail*/

	/****************************************************************** 
	Half Full Simple Set 
	******************************************************************/
	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(9);SSDel(10);SSSize();
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 23);
		 printf("There was no Exception thrown\n");
		 printf("Expected Exception was %s\n", getException(1));
	 }
	 CATCH {
		 if (EXnum__ != (1)) {
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 23);
			 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
		 }
	 }
 	 FINALLY
	 ETRY;
	
	/* Should Fail*/
   TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);
		 if (SSSize() != 1){
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 24);
			 printf("Actual Value was %d\n", SSSize());
	       printf("Expected Value was %d\n", 1);
		 }
	 }
	 CATCH {
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 24);
		 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
	 }
	 FINALLY
	 ETRY;
	

	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);
		 if (SSIsMem(10) != 1){
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 25);
			 printf("Actual Value was %d\n", SSIsMem(10));
	       printf("Expected Value was %d\n", 1);
		 }
	 }
	 CATCH {
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 25);
		 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
	 }
	 FINALLY
	 ETRY;
	


	/****************************************************************** 
	Full Simple Set 	
	******************************************************************/
	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSAdd(10);
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 30);
		 printf("There was no Exception thrown\n");
		 printf("Expected Exception was %s\n", getException(DuplicateExc));
	 }
	 CATCH {
		 if (EXnum__ != (DuplicateExc)) {
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 30);
			 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
		 }
	 }
 	 FINALLY
	 ETRY;
	

	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSAdd(10);
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 31);
		 printf("There was no Exception thrown\n");
		 printf("Expected Exception was %s\n", getException(FullExc));
	 }
	 CATCH {
		 if (EXnum__ != (FullExc)) {
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 31);
			 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
		 }
	 }
 	 FINALLY
	 ETRY;
	
	/* Should Fail*/
	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSAdd(11);
		 if (SSSize() != 2){
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 32);
			 printf("Actual Value was %d\n", SSSize());
	       printf("Expected Value was %d\n", 2);
		 }
	 }
	 CATCH {
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 32);
		 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
	 }
	 FINALLY
	 ETRY;
	

	TRY {
		 cew_Test_Count = cew_Test_Count + 1;
		 SSInit();SSAdd(10);SSAdd(11);SSAdd(12);
		 cew_Error_Count = cew_Error_Count + 1;
		 printf("Test Case ERROR (Ecase) in script at line number %d\n", 33);
		 printf("There was no Exception thrown\n");
		 printf("Expected Exception was %s\n", getException(FullExc));
	 }
	 CATCH {
		 if (EXnum__ != (FullExc)) {
			 cew_Error_Count = cew_Error_Count + 1;
			 printf("Test Case ERROR (Ncase) in script at line number %d\n", 33);
			 printf("Unexpected Exception thrown was %s\n", getException(EXnum__));
		 }
	 }
 	 FINALLY
	 ETRY;
	


	printf("\n**********Summary**********\n");
	 printf("Total number of test cases = %d\n", cew_Test_Count);
	 printf("Total number of test cases in error = %d\n", cew_Error_Count);
	

	
	return 0;
}
/**
 *  This is a difficult method.  What we are doing is trying to
 *  call a static method with a list of arguments.  Similar to 
 *  a varargs call, we need to marshal the Values into their
 *  Java equivalents and make the proper call.
 *  
 * @param type the return type of the method
 * @param className the full (package / name) name of the java class
 * @param methodName the name of the method being invoked
 * @param signature the method signature (ex: "(Ljava/lang/String;I)V" )
 *    that describes the param and return types of the method.
 * @param retval the return value of the java method
 * @return true if the call was successful, else false.  This is not
 *    the return value of the method.    
 */    
bool JavaBinderyImpl::callStatic(int type,
                        const String &className,
                        const String &methodName,
                        const String &signature,
                        const std::vector<Value> &params,
                        Value &retval)
{
    jclass cls = env->FindClass(className.c_str());
    if (!cls)
        {
        err("Could not find class '%s' : %s",
		       className.c_str(), getException().c_str());
        return false;
        }
    jmethodID mid = env->GetStaticMethodID(cls,
                methodName.c_str(), signature.c_str());
    if (!mid)
        {
        err("Could not find method '%s:%s/%s' : %s",
		        className.c_str(), methodName.c_str(),
			    signature.c_str(), getException().c_str());
        return false;
        }
    /**
     * Assemble your parameters into a form usable by JNI
     */
    jvalue *jvals = new jvalue[params.size()];
    for (unsigned int i=0 ; i<params.size() ; i++)
        {
        Value v = params[i];
        switch (v.getType())
            {
            case Value::BIND_BOOLEAN:
                {
                jvals[i].z = (jboolean)v.getBoolean();
                break;
                }
            case Value::BIND_INT:
                {
                jvals[i].i = (jint)v.getInt();
                break;
                }
            case Value::BIND_DOUBLE:
                {
                jvals[i].d = (jdouble)v.getDouble();
                break;
                }
            case Value::BIND_STRING:
                {
                jvals[i].l = (jobject) env->NewStringUTF(v.getString().c_str());
                break;
                }
            default:
                {
                err("Unknown value type: %d", v.getType());
                return false;
                }
            }
        }
    switch (type)
        {
        case Value::BIND_VOID:
            {
            env->CallStaticVoidMethodA(cls, mid, jvals);
            break;
            }
        case Value::BIND_BOOLEAN:
            {
            jboolean ret = env->CallStaticBooleanMethodA(cls, mid, jvals);
            if (ret == JNI_TRUE) //remember, don't truncate
                retval.setBoolean(true);
            else
                retval.setBoolean(false);
            break;
            }
        case Value::BIND_INT:
            {
            jint ret = env->CallStaticIntMethodA(cls, mid, jvals);
            retval.setInt(ret);
            break;
            }
        case Value::BIND_DOUBLE:
            {
            jdouble ret = env->CallStaticDoubleMethodA(cls, mid, jvals);
            retval.setDouble(ret);
            break;
            }
        case Value::BIND_STRING:
            {
            jobject ret = env->CallStaticObjectMethodA(cls, mid, jvals);
            jstring jstr = (jstring) ret;
            const char *str = env->GetStringUTFChars(jstr, JNI_FALSE);
            retval.setString(str);
            env->ReleaseStringUTFChars(jstr, str);
            break;
            }
        default:
            {
            err("Unknown return type: %d", type);
            return false;
            }
        }
    delete jvals;
    String errStr = getException();
    if (errStr.size()>0)
        {
        err("callStatic: %s", errStr.c_str());
        return false;
		}
    return true;
}