Beispiel #1
0
    BackgroundJobProcessor::~BackgroundJobProcessor()
    {
        // This should appear to be called from the same thread from which this instance was created
        Assert(IsClosed());

        if (parallelThreadData)
        {
            for (unsigned int i = 0; i < this->threadCount; i++)
            {
                HeapDelete(parallelThreadData[i]);
            }
            HeapDeleteArray(this->maxThreadCount, parallelThreadData);
        }
    }
Beispiel #2
0
already_AddRefed<Promise>
MediaKeySession::Update(const ArrayBufferViewOrArrayBuffer& aResponse, ErrorResult& aRv)
{
  nsRefPtr<DetailedPromise> promise(MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }
  nsTArray<uint8_t> data;
  if (IsClosed() || !mKeys->GetCDMProxy()) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
                         NS_LITERAL_CSTRING("Session is closed or was not properly initialized"));
    EME_LOG("MediaKeySession[%p,'%s'] Update() failed, session is closed or was not properly initialised.",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    return promise.forget();
  }
  if (!CopyArrayBufferViewOrArrayBufferData(aResponse, data)) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR,
                         NS_LITERAL_CSTRING("Invalid response buffer"));
    EME_LOG("MediaKeySession[%p,'%s'] Update() failed, invalid response buffer",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    return promise.forget();
  }


#ifdef PR_LOGGING
  // Convert response to base64 for easier logging.
  // Note: UpdateSession() Move()s the data out of the array, so we have
  // to copy it here.
  nsAutoCString base64Response;
  nsDependentCSubstring rawResponse(reinterpret_cast<const char*>(data.Elements()),
    data.Length());
  if (NS_FAILED(Base64Encode(rawResponse, base64Response))) {
    NS_WARNING("Failed to base64 encode response for logging");
  }
#endif

  PromiseId pid = mKeys->StorePromise(promise);
  mKeys->GetCDMProxy()->UpdateSession(mSessionId,
                                      pid,
                                      data);

  EME_LOG("MediaKeySession[%p,'%s'] Update() sent to CDM, "
          "promiseId=%d Response(base64)='%s'",
           this,
           NS_ConvertUTF16toUTF8(mSessionId).get(),
           pid,
           base64Response.get());

  return promise.forget();
}
Beispiel #3
0
    bool BackgroundJobProcessor::RemoveJob(Job *const job)
    {
        // This function is called from inside the lock

        Assert(job);
        Assert(managers.Contains(job->Manager()));
        Assert(!IsClosed());

        if (IsBeingProcessed(job))
        {
            return false;
        }
        return __super::RemoveJob(job);
    }
Beispiel #4
0
bool ON_ArcCurve::IsContinuous(
    ON::continuity c,
    double t, 
    int*,   // hint                - formal parameter intentionally ignored in this virtual function
    double, // point_tolerance     - formal parameter intentionally ignored in this virtual function
    double, // d1_tolerance        - formal parameter intentionally ignored in this virtual function
    double, // d2_tolerance        - formal parameter intentionally ignored in this virtual function
    double, // cos_angle_tolerance - formal parameter intentionally ignored in this virtual function
    double  // curvature_tolerance - formal parameter intentionally ignored in this virtual function
    ) const
{
  // 20 March 2003 Dale Lear
  //      Added this override of IsContinuous() to
  //      speed queries and support the
  //      locus favors of ON::continuity.

  bool rc = true;

  if ( !IsClosed() )
  {
    switch(c)
    {
    case ON::unknown_continuity:
    case ON::C0_continuous:
    case ON::C1_continuous:
    case ON::C2_continuous:
    case ON::G1_continuous:
    case ON::G2_continuous:
    case ON::Cinfinity_continuous:
    case ON::Gsmooth_continuous:
      // rc = true;
      break;

    case ON::C0_locus_continuous:
    case ON::C1_locus_continuous:
    case ON::C2_locus_continuous:
    case ON::G1_locus_continuous:
    case ON::G2_locus_continuous:
      // open arc is locus discontinuous at end parameter.
      // By convention (see ON::continuity comments) it
      // is locus continuous at start parameter.
      if ( t >= Domain()[1] )
        rc = false;
      break;
    }
  }

  return rc;
}
NS_IMETHODIMP
nsBaseContentStream::ReadSegments(nsWriteSegmentFun fun, void *closure,
                                  PRUint32 count, PRUint32 *result)
{
    *result = 0;

    if (mStatus == NS_BASE_STREAM_CLOSED)
        return NS_OK;

    // No data yet
    if (!IsClosed() && IsNonBlocking())
        return NS_BASE_STREAM_WOULD_BLOCK;

    return mStatus;
}
Beispiel #6
0
int ON_Surface::IsAtSeam(double s, double t) const

{
  int rc = 0;
  int i;
  for (i=0; i<2; i++){
    if (!IsClosed(i))
      continue;
    double p = (i) ? t : s;
    if (p == Domain(i)[0] || p == Domain(i)[1])
      rc += (i+1);
  }

  return rc;
}
Beispiel #7
0
    void BackgroundJobProcessor::AddJob(Job *const job, const bool prioritize)
    {
        // This function is called from inside the lock

        Assert(job);
        Assert(managers.Contains(job->Manager()));
        Assert(!IsClosed());

        if(numJobs + 1 == 0)
            Js::Throw::OutOfMemory(); // Overflow: job counts we use are int32's.
        ++numJobs;

        __super::AddJob(job, prioritize);
        IndicateNewJob();
    }
already_AddRefed<Promise>
MediaKeySession::Close(ErrorResult& aRv)
{
  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }
  if (IsClosed() || !mKeys->GetCDMProxy()) {
    promise->MaybeResolve(JS::UndefinedHandleValue);
    return promise.forget();
  }
  mKeys->GetCDMProxy()->CloseSession(mSessionId, mKeys->StorePromise(promise));

  return promise.forget();
}
// static
IndexedDatabaseManager*
IndexedDatabaseManager::GetOrCreate()
{
  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");

  if (IsClosed()) {
    NS_ERROR("Calling GetOrCreate() after shutdown!");
    return nullptr;
  }

  if (!gDBManager) {
    sIsMainProcess = XRE_IsParentProcess();

    if (sIsMainProcess && Preferences::GetBool("disk_space_watcher.enabled", false)) {
      // See if we're starting up in low disk space conditions.
      nsCOMPtr<nsIDiskSpaceWatcher> watcher =
        do_GetService(DISKSPACEWATCHER_CONTRACTID);
      if (watcher) {
        bool isDiskFull;
        if (NS_SUCCEEDED(watcher->GetIsDiskFull(&isDiskFull))) {
          sLowDiskSpaceMode = isDiskFull;
        }
        else {
          NS_WARNING("GetIsDiskFull failed!");
        }
      }
      else {
        NS_WARNING("No disk space watcher component available!");
      }
    }

    RefPtr<IndexedDatabaseManager> instance(new IndexedDatabaseManager());

    nsresult rv = instance->Init();
    NS_ENSURE_SUCCESS(rv, nullptr);

    if (gInitialized.exchange(true)) {
      NS_ERROR("Initialized more than once?!");
    }

    gDBManager = instance;

    ClearOnShutdown(&gDBManager);
  }

  return gDBManager;
}
Beispiel #10
0
    void BackgroundJobProcessor::AddManager(JobManager *const manager)
    {
        Assert(manager);

        IterateBackgroundThreads([&manager](ParallelThreadData *threadData){
            manager->ProcessorThreadSpecificCallBack(threadData->GetPageAllocator());
            return false;
        });

        AutoCriticalSection lock(&criticalSection);
        Assert(!IsClosed());

        JobProcessor::AddManager(manager);


        IndicateNewJob();
    }
already_AddRefed<Promise>
MediaKeySession::Close(ErrorResult& aRv)
{
  RefPtr<DetailedPromise> promise(MakePromise(aRv,
    NS_LITERAL_CSTRING("MediaKeySession.close")));
  if (aRv.Failed()) {
    return nullptr;
  }
  // 1. Let session be the associated MediaKeySession object.
  // 2. If session is closed, return a resolved promise.
  if (IsClosed()) {
    EME_LOG("MediaKeySession[%p,'%s'] Close() already closed",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    promise->MaybeResolveWithUndefined();
    return promise.forget();
  }
  // 3. If session's callable value is false, return a promise rejected
  // with an InvalidStateError.
  if (!IsCallable()) {
    EME_LOG("MediaKeySession[%p,''] Close() called before sessionId set by CDM", this);
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
      NS_LITERAL_CSTRING("MediaKeySession.Close() called before sessionId set by CDM"));
    return promise.forget();
  }
  if (!mKeys->GetCDMProxy()) {
    EME_LOG("MediaKeySession[%p,'%s'] Close() null CDMProxy",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
      NS_LITERAL_CSTRING("MediaKeySession.Close() lost reference to CDM"));
    return promise.forget();
  }
  // 4. Let promise be a new promise.
  PromiseId pid = mKeys->StorePromise(promise);
  // 5. Run the following steps in parallel:
  // 5.1 Let cdm be the CDM instance represented by session's cdm instance value.
  // 5.2 Use cdm to close the session associated with session.
  mKeys->GetCDMProxy()->CloseSession(mSessionId, pid);

  EME_LOG("MediaKeySession[%p,'%s'] Close() sent to CDM, promiseId=%d",
          this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid);

  // Session Closed algorithm is run when CDM causes us to run OnSessionClosed().

  // 6. Return promise.
  return promise.forget();
}
const OPT<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfIntersecting() const
{
    for( int s1 = 0; s1 < SegmentCount(); s1++ )
    {
        for( int s2 = s1 + 1; s2 < SegmentCount(); s2++ )
        {
            const VECTOR2I s2a = CSegment( s2 ).A, s2b = CSegment( s2 ).B;

            if( s1 + 1 != s2 && CSegment( s1 ).Contains( s2a ) )
            {
                INTERSECTION is;
                is.our = CSegment( s1 );
                is.their = CSegment( s2 );
                is.p = s2a;
                return is;
            }
            else if( CSegment( s1 ).Contains( s2b ) &&
                     // for closed polylines, the ending point of the
                     // last segment == starting point of the first segment
                     // this is a normal case, not self intersecting case
                     !( IsClosed() && s1 == 0 && s2 == SegmentCount()-1 ) )
            {
                INTERSECTION is;
                is.our = CSegment( s1 );
                is.their = CSegment( s2 );
                is.p = s2b;
                return is;
            }
            else
            {
                OPT_VECTOR2I p = CSegment( s1 ).Intersect( CSegment( s2 ), true );

                if( p )
                {
                    INTERSECTION is;
                    is.our = CSegment( s1 );
                    is.their = CSegment( s2 );
                    is.p = *p;
                    return is;
                }
            }
        }
    }

    return OPT<SHAPE_LINE_CHAIN::INTERSECTION>();
}
/**--------------------------------------------------------------------------<BR>
C2DLineBaseSet::AddIfCommonEnd
\brief Adds the points of another to this if they have a common end which is either
the first or last point. Returns true if there was a match.
<P>---------------------------------------------------------------------------*/
bool C2DLineBaseSet::AddIfCommonEnd(C2DLineBaseSet& Other)
{
	assert(!IsClosed());
	assert(!Other.IsClosed());

	int nThisCount = size() ;
	if (nThisCount < 1) return false;

	int nOtherCount = Other.size();
	if (nOtherCount < 1) return false;

	if ( GetAt(0)->GetPointFrom() == Other.GetAt(0)->GetPointFrom())
	{
		ReverseDirection();

		*this << Other;

		return true;
	}
	else if( GetAt(0)->GetPointFrom() == Other.GetAt(nOtherCount - 1)->GetPointTo() )
	{
		ReverseDirection();

		Other.ReverseDirection();

		*this << Other;

		return true;
	}
	else if (GetAt(nThisCount - 1)->GetPointTo() == Other.GetAt(0)->GetPointFrom())
	{
		*this << Other;

		return true;
	}	
	else if (GetAt(nThisCount - 1)->GetPointTo() == Other.GetAt(nOtherCount - 1)->GetPointTo() )
	{
		Other.ReverseDirection();	

		*this << Other;

		return true;
	}	

	return false;
}
Beispiel #14
0
bool CZipArchive::SetGlobalComment(const CString &szComment)
{
	if (IsClosed())
	{
		TRACE(_T("ZipArchive is closed.\n"));
		return false;
	}
	if (m_storage.IsSpanMode() == -1)
	{
		TRACE(_T("You cannot modify the global comment of the existing disk spanning archive.\n"));
		return false;
	}
	
	m_centralDir.m_szComment = szComment;
	m_centralDir.RemoveFromDisk();
	return true;
}
Beispiel #15
0
    void JobProcessor::AddJob(Job *const job, const bool prioritize)
    {
        // This function is called from inside the lock

        Assert(job);
        Assert(managers.Contains(job->Manager()));
        Assert(!IsClosed());

        if (job->Manager()->numJobsAddedToProcessor + 1 == 0)
            Js::Throw::OutOfMemory();  // Overflow: job counts we use are int32's.
        ++job->Manager()->numJobsAddedToProcessor;

        if (prioritize)
            jobs.LinkToBeginning(job);
        else
            jobs.LinkToEnd(job);
    }
Beispiel #16
0
NS_IMETHODIMP
nsFileUploadContentStream::AsyncWait(nsIInputStreamCallback *callback,
                                     uint32_t flags, uint32_t count,
                                     nsIEventTarget *target)
{
  nsresult rv = nsBaseContentStream::AsyncWait(callback, flags, count, target);
  if (NS_FAILED(rv) || IsClosed())
    return rv;

  if (IsNonBlocking()) {
    nsCOMPtr<nsIRunnable> callback =
      NS_NewRunnableMethod(this, &nsFileUploadContentStream::OnCopyComplete);
    mCopyEvent->Dispatch(callback, mSink, target);
  }

  return NS_OK;
}
Beispiel #17
0
void BaseSession::Recv(Array& raw_data)
{
	if (IsClosed())
		return;
	stream_ibuffer_.Insert(stream_ibuffer_.End(), raw_data.Begin(), raw_data.Size());

	for (;;)
	{
		if (stream_ibuffer_.Size() < 2)
			return;
		uint16_t len = *reinterpret_cast<uint16_t *>(stream_ibuffer_.Begin());
		if (stream_ibuffer_.Size() < 2 + len)
			return;
		Array proto(static_cast<char *>(stream_ibuffer_.Begin())+2, len);
		OnAfterRecv(proto);
		stream_ibuffer_.Erase(stream_ibuffer_.Begin(), 2+len);
	}
}
Beispiel #18
0
bool ON_NurbsCurve::Morph( const ON_SpaceMorph& morph )
{
  DestroyCurveTree();
  ON_BOOL32 bIsClosed = IsClosed();
  ON_BOOL32 bIsPeriodic = IsPeriodic();
  morph.MorphPointList( m_dim, m_is_rat, m_cv_count, m_cv_stride, m_cv );
  if ( bIsPeriodic )
  {
    int i, deg = m_order-1;
    for ( i = 0; i < deg; i++ )
      SetCV( m_cv_count-deg+i, ON::intrinsic_point_style, CV(i) );
  }
  else if ( bIsClosed )
  {
    SetCV( m_cv_count-1, ON::intrinsic_point_style, CV(0) );
  }
  return true;
}
Beispiel #19
0
int CZipArchive::FindFile(CString szFileName, bool bCaseSensitive)
{
	if (IsClosed())
	{
		TRACE(_T("ZipArchive is closed.\n"));
		return (int)-1;
	}
	
	for (WORD i = 0; i < GetNoEntries(); i++)
	{
		CFileHeader fh;
		GetFileInfo(fh, i);
		CString temp = fh.m_szFileName;
		if ((bCaseSensitive ? temp.Collate(szFileName) : temp.CollateNoCase(szFileName)) == 0)
			return (int)i;
	}
	return (int) - 1;
}
Beispiel #20
0
bool CZipArchive::GetFileInfo(CFileHeader & fhInfo, WORD uIndex)
{
	if (IsClosed())
	{
		TRACE(_T("ZipArchive is closed.\n"));
		return false;
	}
	
	if (!m_centralDir.IsValidIndex(uIndex))
		return false;
	
	fhInfo = *(m_centralDir.m_headers[uIndex]);
	//if (m_bOemCompatible)
	//	fhInfo.m_szFileName.OemToAnsi();
	if (m_bSlashChange)
		fhInfo.m_szFileName.Replace(_T('/'), _T('\\'));
	return true;
}
Beispiel #21
0
void
MediaKeySession::DispatchKeysChange()
{
  if (IsClosed()) {
    return;
  }
  DebugOnly<nsresult> rv =
    nsContentUtils::DispatchTrustedEvent(mKeys->GetOwnerDoc(),
                                         this,
                                         NS_LITERAL_STRING("keyschange"),
                                         false,
                                         false);
#ifdef DEBUG
  if (NS_FAILED(rv)) {
    NS_WARNING("Failed to dispatch keyschange event");
  }
#endif
}
bool
AbstractTaskFactory::Validate()
{
  ClearValidationErrors();

  bool valid = true;

  if (!task.HasStart()) {
    AddValidationError(TaskValidationErrorType::NO_VALID_START);
    valid = false;
  }
  if (!task.HasFinish()) {
    AddValidationError(TaskValidationErrorType::NO_VALID_FINISH);
    valid = false;
  }

  if (constraints.is_closed && !IsClosed()) {
    AddValidationError(TaskValidationErrorType::TASK_NOT_CLOSED);
    valid = false;
  }

  if (constraints.IsFixedSize()) {
    if (task.TaskSize() != constraints.max_points) {
      AddValidationError(TaskValidationErrorType::INCORRECT_NUMBER_TURNPOINTS);
      valid = false;
    }
  } else {
    if (task.TaskSize() < constraints.min_points) {
      AddValidationError(TaskValidationErrorType::UNDER_MIN_TURNPOINTS);
      valid = false;
    }
    if (task.TaskSize() > constraints.max_points) {
      AddValidationError(TaskValidationErrorType::EXCEEDS_MAX_TURNPOINTS);
      valid = false;
    }
  }

  if (constraints.homogeneous_tps && !IsHomogeneous()) {
    AddValidationError(TaskValidationErrorType::TASK_NOT_HOMOGENEOUS);
    valid = false;
  }

  return valid;
}
Beispiel #23
0
already_AddRefed<Promise>
MediaKeySession::Update(const ArrayBufferViewOrArrayBuffer& aResponse, ErrorResult& aRv)
{
  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }
  nsTArray<uint8_t> data;
  if (IsClosed() ||
      !mKeys->GetCDMProxy() ||
      !CopyArrayBufferViewOrArrayBufferData(aResponse, data)) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
    return promise.forget();
  }
  mKeys->GetCDMProxy()->UpdateSession(mSessionId,
                                      mKeys->StorePromise(promise),
                                      data);
  return promise.forget();
}
Beispiel #24
0
void Socket::start_async_send()
{
    if( IsClosed() )
        return;

    if( m_OutActive )
        return;
    
    if ( m_OutBuffer->length() == 0 )
    {
        m_OutActive = false;
        return;
    }

    m_OutActive = true;

    m_socket.async_write_some( boost::asio::buffer( m_OutBuffer->rd_ptr(), m_OutBuffer->length() ),
                               boost::bind( &Socket::on_write_complete, shared_from_this(), 
                                            boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred ) );
}
Beispiel #25
0
already_AddRefed<Promise>
MediaKeySession::Remove(ErrorResult& aRv)
{
  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }
  if (mSessionType != SessionType::Persistent) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
    // "The operation is not supported on session type sessions."
    return promise.forget();
  }
  if (IsClosed() || !mKeys->GetCDMProxy()) {
    promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
    // "The session is closed."
    return promise.forget();
  }
  mKeys->GetCDMProxy()->RemoveSession(mSessionId, mKeys->StorePromise(promise));
  return promise.forget();
}
Beispiel #26
0
bool CZipArchive::SetFileComment(WORD uIndex, CString szComment)
{
	if (IsClosed())
	{
		TRACE(_T("ZipArchive is closed.\n"));
		return false;
	}
	if (m_storage.IsSpanMode() == -1)
	{
		TRACE(_T("You cannot modify the global comment of the existing disk spanning archive.\n"));
		return false;
	}
	
	if (!m_centralDir.IsValidIndex(uIndex))
		return false;
	m_centralDir.m_headers[uIndex]->m_szComment = szComment;
	m_centralDir.m_headers[uIndex]->ValidateComment();
	m_centralDir.RemoveFromDisk();
	return true;
}
Beispiel #27
0
/////////////////////////////////////////////////////////////////////////////
// Test for angle
/////////////////////////////////////////////////////////////////////////////
bool CDiscretizedLine::IsAngle(int i) const
{
 if ((i == 0 || i == Size() - 1) && !IsClosed())
  return true;

 int Next = NextIndex(i);
 int Prev = PreviousIndex(i);

 double x1 = vx[Next] - vx[i];
 double y1 = vy[Next] - vy[i];
 double x2 = vx[Prev] - vx[i];
 double y2 = vy[Prev] - vy[i];

 double det = x1 * y2 - x2 * y1;

 double n1 = x1 * x1 + y1 * y1;
 double n2 = x2 * x2 + y2 * y2;

 return std::fabs(det / std::sqrt(n1 * n2)) > 0.4; // ???
}
Beispiel #28
0
void Socket::close()
{
    if( IsClosed() )
        return;

    m_closing = true;

    try
    {
        if( m_socket.is_open() )
        {
            m_socket.shutdown( boost::asio::socket_base::shutdown_both );
            m_socket.close();
        }
    }
    catch( boost::system::error_code& e)
    {
        sLog.outError("Socket::close: error occurred while closing socket = %s", e.message().c_str());
    }
}
Beispiel #29
0
void CMission::OnNewSystem (CSystem *pSystem)

//	OnNewSystem
//
//	We are in a new system

{
    //	Ignore any closed missions (completed missions)

    if (IsClosed())
        return;

    //	Resolve owner

    m_pOwner.Resolve();

    //	Clear any object references (because they might belong to a different
    //	system).

    ClearObjReferences();
}
Beispiel #30
0
already_AddRefed<Promise>
MediaKeySession::Close(ErrorResult& aRv)
{
  nsRefPtr<Promise> promise(mKeys->MakePromise(aRv));
  if (aRv.Failed()) {
    return nullptr;
  }
  if (IsClosed() || !mKeys->GetCDMProxy()) {
    EME_LOG("MediaKeySession[%p,'%s'] Close() already closed",
            this, NS_ConvertUTF16toUTF8(mSessionId).get());
    promise->MaybeResolve(JS::UndefinedHandleValue);
    return promise.forget();
  }
  PromiseId pid = mKeys->StorePromise(promise);
  mKeys->GetCDMProxy()->CloseSession(mSessionId, mKeys->StorePromise(promise));

  EME_LOG("MediaKeySession[%p,'%s'] Close() sent to CDM, promiseId=%d",
          this, NS_ConvertUTF16toUTF8(mSessionId).get(), pid);

  return promise.forget();
}