Exemple #1
0
 void scheduler_object::add_thread(size_t nthr) {
     std::lock_guard<std::mutex> guard(mtx_);
     scheduler_ptr_t pthis(shared_from_this());
     for(size_t i=0; i<nthr; i++) {
         threads_.push_back(std::thread(std::bind(run_in_this_thread, pthis)));
     }
 }
Exemple #2
0
    void scheduler_object::start(size_t nthr) {
        std::lock_guard<std::mutex> guard(mtx_);
        if (threads_.size()>0) {
            // Already started
            return;
        }

        check_timer.reset(new timer_t(io_service_));
        check_timer->expires_from_now(std::chrono::milliseconds(50));
        scheduler_ptr_t pthis(shared_from_this());
        check_timer->async_wait(std::bind(&scheduler_object::on_check_timer, pthis, std::placeholders::_1));
        for(size_t i=0; i<nthr; i++) {
            threads_.push_back(std::thread(std::bind(run_in_this_thread, pthis)));
        }
    }
//create bytestream
//create media-source
HRESULT FttpSchemeHandler::BeginCreateObject(LPCWSTR url,
                                             DWORD flags,
                                             IPropertyStore* ,  // not used
                                             IUnknown**cancel_cookie,
                                             IMFAsyncCallback*callback,
                                             IUnknown*s) {
  if(cancel_cookie)
    *cancel_cookie = nullptr;

  if ((flags & MF_RESOLUTION_WRITE) || !(flags & MF_RESOLUTION_MEDIASOURCE))
    return E_INVALIDARG;
  if (caller_result)
    return E_FAIL;  // only one session allowed

  uri = fttp_resolver().resolve(url);
  auto hr = uri.validate() ? S_OK : E_INVALID_PROTOCOL_FORMAT;

  IMFSchemeHandlerPtr pthis(this);

  if (SUCCEEDED(hr)) hr = MFCreateAsyncResult(nullptr, callback, s, &caller_result);
  if (SUCCEEDED(hr) && uri.type == fttp_type::url)
    scatter_tar_file_handler().async_check(uri.true_url).then([this, pthis](scheme_check_result result) {
      assert(!http_stream && !source_creator);
      content_type = result.content_type;
      CopyMemory(magic, result.maigic, sizeof(magic));
      HRESULT hr = result.error; // (result.error < 0) ? (result.error | make_sure_negativei32) : S_OK;
      if (SUCCEEDED(hr) && (http_stream || source_creator)) hr = E_FAIL;
      if (SUCCEEDED(hr)) 
        hr = MakeAndInitialize<ProgressiveHttpStream, IMFByteStream>(&http_stream, result.url.c_str(), result.content_length);
      if (SUCCEEDED(hr)) hr = BeginCreateMediaSource();

      if (FAILED(hr)) {
        caller_result->SetStatus(hr);
        hr = MFInvokeCallback(caller_result.Get());
      }
    });
  else if (SUCCEEDED(hr)) {
    auto fp = uri.true_url;
    hr = MFBeginCreateFile(MF_ACCESSMODE_READ, MF_OPENMODE_FAIL_IF_NOT_EXIST, MF_FILEFLAGS_NONE, fp.c_str(), &when_create_bytestream, nullptr, nullptr);
  } 
  return hr;
}
Exemple #4
0
CBotLeftExpr* CBotLeftExpr::Compile(CBotToken* &p, CBotCStack* pStack)
{
    CBotCStack* pStk = pStack->TokenStack();

    pStk->SetStartError(p->GetStart());

    // is it a variable name?
    if (p->GetType() == TokenTypVar)
    {
        CBotLeftExpr* inst = new CBotLeftExpr();    // creates the object

        inst->SetToken(p);

        CBotVar*     var;

        if (nullptr != (var = pStk->FindVar(p)))   // seek if known variable
        {
            inst->m_nIdent = var->GetUniqNum();
            if (inst->m_nIdent > 0 && inst->m_nIdent < 9000)
            {
                if (CBotFieldExpr::CheckProtectionError(pStk, nullptr, var, CBotVar::ProtectionLevel::ReadOnly))
                {
                    pStk->SetError(CBotErrPrivate, p);
                    goto err;
                }
                // this is an element of the current class
                // adds the equivalent of this. before
                CBotToken pthis("this");
                inst->SetToken(&pthis);
                inst->m_nIdent = -2;    // indent for this

                CBotFieldExpr* i = new CBotFieldExpr();     // new element
                i->SetToken(p);     // keeps the name of the token
                inst->AddNext3(i);  // add after

                var = pStk->FindVar(pthis);
                var = var->GetItem(p->GetString());
                i->SetUniqNum(var->GetUniqNum());
            }
            p = p->GetNext();   // next token

            while (true)
            {
                if (var->GetType() == CBotTypArrayPointer)
                {
                    if (IsOfType( p, ID_OPBRK ))
                    {
                        CBotIndexExpr* i = new CBotIndexExpr();
                        i->m_expr = CBotExpression::Compile(p, pStk);
                        inst->AddNext3(i);  // add to the chain

                        var = (static_cast<CBotVarArray*>(var))->GetItem(0,true);    // gets the component [0]

                        if (i->m_expr == nullptr)
                        {
                            pStk->SetError(CBotErrBadIndex, p->GetStart());
                            goto err;
                        }

                        if (!pStk->IsOk() || !IsOfType( p, ID_CLBRK ))
                        {
                            pStk->SetError(CBotErrCloseIndex, p->GetStart());
                            goto err;
                        }
                        continue;
                    }
                }

                if (var->GetType(CBotVar::GetTypeMode::CLASS_AS_POINTER) == CBotTypPointer)                // for classes
                {
                    if (IsOfType(p, ID_DOT))
                    {
                        CBotToken* pp = p;

                        CBotFieldExpr* i = new CBotFieldExpr();            // new element
                        i->SetToken(pp);                                // keeps the name of the token
                        inst->AddNext3(i);                                // adds after

                        if (p->GetType() == TokenTypVar)                // must be a name
                        {
                            CBotVar*   preVar = var;
                            var = var->GetItem(p->GetString());            // get item correspondent
                            if (var != nullptr)
                            {
                                if (CBotFieldExpr::CheckProtectionError(pStk, preVar, var,
                                                                        CBotVar::ProtectionLevel::ReadOnly))
                                {
                                    pStk->SetError(CBotErrPrivate, pp);
                                    goto err;
                                }

                                i->SetUniqNum(var->GetUniqNum());
                                p = p->GetNext();                        // skips the name
                                continue;
                            }
                            pStk->SetError(CBotErrUndefItem, p);
                        }
                        pStk->SetError(CBotErrUndefClass, p->GetStart());
                        goto err;
                    }
                }
                break;
            }


            if (pStk->IsOk()) return static_cast<CBotLeftExpr*> (pStack->Return(inst, pStk));
        }
        pStk->SetError(CBotErrUndefVar, p);
err:
        delete inst;
        return static_cast<CBotLeftExpr*> ( pStack->Return(nullptr, pStk));
    }

    return static_cast<CBotLeftExpr*> ( pStack->Return(nullptr, pStk));
}