Example #1
0
Promise<RefreshResult> Client::Refresh (
    String access_token,
    String client_token,
    Nullable<Profile> profile
) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        refresh_token_key,
        std::move(access_token),
        refresh_client_token_key,
        std::move(client_token)
    );
    if (!profile.IsNull()) obj.Add(
            refresh_profile_key,
            profile->ToJSON()
        );

    //	Dispatch request
    return dispatch<RefreshResult>(
               refresh_endpoint,
               std::move(obj)
           );

}
Example #2
0
Promise<AuthenticateResult> Client::Authenticate (
    String username,
    String password,
    Nullable<String> client_token,
    Nullable<Agent> agent
) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        auth_username_key,
        std::move(username),
        auth_password_key,
        std::move(password)
    );
    if (!client_token.IsNull()) obj.Add(
            auth_client_token_key,
            std::move(*client_token)
        );
    if (!agent.IsNull()) obj.Add(
            auth_agent_key,
            agent->ToJSON()
        );

    //	Dispatch request
    return dispatch<AuthenticateResult>(
               auth_endpoint,
               std::move(obj)
           );

}
Example #3
0
// https://w3c.github.io/web-animations/#set-the-animation-playback-rate
void
Animation::SetPlaybackRate(double aPlaybackRate)
{
  if (aPlaybackRate == mPlaybackRate) {
    return;
  }

  AutoMutationBatchForAnimation mb(*this);

  Nullable<TimeDuration> previousTime = GetCurrentTime();
  mPlaybackRate = aPlaybackRate;
  if (!previousTime.IsNull()) {
    SetCurrentTime(previousTime.Value());
  }

  // In the case where GetCurrentTime() returns the same result before and
  // after updating mPlaybackRate, SetCurrentTime will return early since,
  // as far as it can tell, nothing has changed.
  // As a result, we need to perform the following updates here:
  // - update timing (since, if the sign of the playback rate has changed, our
  //   finished state may have changed),
  // - dispatch a change notification for the changed playback rate, and
  // - update the playback rate on animations on layers.
  UpdateTiming(SeekFlag::DidSeek, SyncNotifyFlag::Async);
  if (IsRelevant()) {
    nsNodeUtils::AnimationChanged(this);
  }
  PostUpdate();
}
void
WebGLContext::GetSupportedExtensions(JSContext *cx, Nullable< nsTArray<nsString> > &retval)
{
    retval.SetNull();
    if (IsContextLost())
        return;

    nsTArray<nsString>& arr = retval.SetValue();

    for (size_t i = 0; i < size_t(WebGLExtensionID_max); i++)
    {
        WebGLExtensionID extension = WebGLExtensionID(i);

        if (IsExtensionSupported(cx, extension)) {
            arr.AppendElement(NS_ConvertUTF8toUTF16(GetExtensionString(extension)));
        }
    }

    /**
     * We keep backward compatibility for these deprecated vendor-prefixed
     * alias. Do not add new ones anymore. Hide it behind the
     * webgl.enable-draft-extensions flag instead.
     */
    if (IsExtensionSupported(cx, WEBGL_lose_context))
        arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_lose_context"));
    if (IsExtensionSupported(cx, WEBGL_compressed_texture_s3tc))
        arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_s3tc"));
    if (IsExtensionSupported(cx, WEBGL_compressed_texture_atc))
        arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_atc"));
    if (IsExtensionSupported(cx, WEBGL_compressed_texture_pvrtc))
        arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_compressed_texture_pvrtc"));
    if (IsExtensionSupported(cx, WEBGL_depth_texture))
        arr.AppendElement(NS_LITERAL_STRING("MOZ_WEBGL_depth_texture"));
}
Example #5
0
void
AnimationPlayer::DoPlay()
{
  // FIXME: When we implement finishing behavior (bug 1074630) we will
  // need to pass a flag so that when we start playing due to a change in
  // animation-play-state we *don't* trigger finishing behavior.

  Nullable<TimeDuration> currentTime = GetCurrentTime();
  if (currentTime.IsNull()) {
    mHoldTime.SetValue(TimeDuration(0));
  } else if (mHoldTime.IsNull()) {
    // If the hold time is null, we are already playing normally
    return;
  }

  // Clear ready promise. We'll create a new one lazily.
  mReady = nullptr;

  mIsPending = true;

  nsIDocument* doc = GetRenderedDocument();
  if (!doc) {
    StartOnNextTick(Nullable<TimeDuration>());
    return;
  }

  PendingPlayerTracker* tracker = doc->GetOrCreatePendingPlayerTracker();
  tracker->AddPlayPending(*this);

  // We may have updated the current time when we set the hold time above
  // so notify source content.
  UpdateSourceContent();
}
Example #6
0
/**
* @return true, if row number was adjusted, false otherwise
*/
static bool AdjustRowNumber(Nullable<Codeword>& codeword, const Nullable<Codeword>& otherCodeword) {
	if (codeword != nullptr && otherCodeword != nullptr
		&& otherCodeword.value().hasValidRowNumber() && otherCodeword.value().bucket() == codeword.value().bucket()) {
		codeword.value().setRowNumber(otherCodeword.value().rowNumber());
		return true;
	}
	return false;
}
// Helper function for converting values of char * to Nullable<std::wstring>
Nullable<std::wstring> GetNullableWString(const std::string& value)
{
    Nullable<std::wstring> ret;
    std::wstring str = Utils::ConvertToUtf16(value);
    wprintf(L"%ls\n", str.c_str());
    ret.SetValue(str);
    return ret;
}
bool HTMLElementImp::evalNoWrap(HTMLElementImp* element)
{
    Nullable<std::u16string> value = element->getAttribute(u"nowrap");
    if (value.hasValue()) {
        element->getStyle().setProperty(u"white-space", u"nowrap", u"non-css");
        return true;
    }
    return false;
}
bool HTMLElementImp::evalValign(HTMLElementImp* element)
{
    Nullable<std::u16string> value = element->getAttribute(u"valign");
    if (value.hasValue()) {
        element->getStyle().setProperty(u"vertical-align", value.value(), u"non-css");
        return true;
    }
    return false;
}
Example #10
0
void
MessageEvent::GetSource(Nullable<OwningWindowProxyOrMessagePort>& aValue) const
{
  if (mWindowSource) {
    aValue.SetValue().SetAsWindowProxy() = mWindowSource;
  } else if (mPortSource) {
    aValue.SetValue().SetAsMessagePort() = mPortSource;
  }
}
Example #11
0
 tagger(CharacterVector dict, CharacterVector model, CharacterVector user,Nullable<CharacterVector> stop) :
   dict_path(dict[0]), model_path(model[0]), user_path(user[0]), stopWords(unordered_set<string>()), taggerseg(dict_path, model_path, user_path)
 {
 	  	  if(!stop.isNull()){
 	    CharacterVector stop_value = stop.get();
 	 	  const char *const stop_path = stop_value[0];
 	 	  _loadStopWordDict(stop_path,stopWords);
 	 }
 }
Example #12
0
void
Animation::SilentlySetPlaybackRate(double aPlaybackRate)
{
  Nullable<TimeDuration> previousTime = GetCurrentTime();
  mPlaybackRate = aPlaybackRate;
  if (!previousTime.IsNull()) {
    SilentlySetCurrentTime(previousTime.Value());
  }
}
Example #13
0
/* static */ nsresult
IccContact::Create(mozContact& aMozContact, nsIIccContact** aIccContact)
{
  *aIccContact = nullptr;
  ErrorResult er;

  // Id
  nsAutoString id;
  aMozContact.GetId(id, er);
  NS_ENSURE_SUCCESS(er.StealNSResult(), NS_ERROR_FAILURE);

  // Names
  Nullable<nsTArray<nsString>> names;
  aMozContact.GetName(names, er);
  NS_ENSURE_SUCCESS(er.StealNSResult(), NS_ERROR_FAILURE);
  if (names.IsNull()) {
    // Set as Empty nsTarray<nsString> for IccContact constructor.
    names.SetValue();
  }

  // Numbers
  Nullable<nsTArray<ContactTelField>> nullableNumberList;
  aMozContact.GetTel(nullableNumberList, er);
  NS_ENSURE_SUCCESS(er.StealNSResult(), NS_ERROR_FAILURE);
  nsTArray<nsString> numbers;
  if (!nullableNumberList.IsNull()) {
    const nsTArray<ContactTelField>& numberList = nullableNumberList.Value();
    for (uint32_t i = 0; i < numberList.Length(); i++) {
      if (numberList[i].mValue.WasPassed()) {
        numbers.AppendElement(numberList[i].mValue.Value());
      }
    }
  }

  // Emails
  Nullable<nsTArray<ContactField>> nullableEmailList;
  aMozContact.GetEmail(nullableEmailList, er);
  NS_ENSURE_SUCCESS(er.StealNSResult(), NS_ERROR_FAILURE);
  nsTArray<nsString> emails;
  if (!nullableEmailList.IsNull()) {
    const nsTArray<ContactField>& emailList = nullableEmailList.Value();
    for (uint32_t i = 0; i < emailList.Length(); i++) {
      if (emailList[i].mValue.WasPassed()) {
        emails.AppendElement(emailList[i].mValue.Value());
      }
    }
  }

  nsCOMPtr<nsIIccContact> iccContact = new IccContact(id,
                                                      names.Value(),
                                                      numbers,
                                                      emails);
  iccContact.forget(aIccContact);

  return NS_OK;
}
bool HTMLElementImp::evalBackground(HTMLElementImp* element)
{
    Nullable<std::u16string> attr = element->getAttribute(u"background");
    if (attr.hasValue()) {
        css::CSSStyleDeclaration style = element->getStyle();
        style.setProperty(u"background-image", u"url(" + attr.value() + u")", u"non-css");
        return true;
    }
    return false;
}
/// <summary>
/// Initializes the device context.
/// </summary>
void BaseTelemetryContext::InitDevice()
{
	Nullable<std::wstring> strOs;
	strOs.SetValue(L"Windows");
	device.SetOs(strOs);

	Nullable<std::wstring> strType;
	strType.SetValue(L"Other");
	device.SetType(strType);
}
bool HTMLElementImp::evalColor(HTMLElementImp* element, const std::u16string& attr, const std::u16string& prop)
{
    Nullable<std::u16string> value = element->getAttribute(attr);
    if (value.hasValue()) {
        css::CSSStyleDeclaration style = element->getStyle();
        style.setProperty(prop, value.value(), u"non-css");
        return true;
    }
    return false;
}
Example #17
0
void
Animation::SilentlySetPlaybackRate(double aPlaybackRate)
{
  Nullable<TimeDuration> previousTime = GetCurrentTime();
  mPlaybackRate = aPlaybackRate;
  if (!previousTime.IsNull()) {
    ErrorResult rv;
    SilentlySetCurrentTime(previousTime.Value());
    MOZ_ASSERT(!rv.Failed(), "Should not assert for non-null time");
  }
}
Example #18
0
void
FileList::Item(uint32_t aIndex, Nullable<OwningFileOrDirectory>& aValue,
               ErrorResult& aRv) const
{
  if (aIndex >= mFilesOrDirectories.Length()) {
    aValue.SetNull();
    return;
  }

  aValue.SetValue(mFilesOrDirectories[aIndex]);
}
Example #19
0
NS_IMETHODIMP
QuotaManagerService::ClearStoragesForPrincipal(nsIPrincipal* aPrincipal,
                                               const nsACString& aPersistenceType,
                                               bool aClearAll,
                                               nsIQuotaRequest** _retval)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(aPrincipal);

  nsCString suffix;
  aPrincipal->OriginAttributesRef().CreateSuffix(suffix);

  if (NS_WARN_IF(aClearAll && !suffix.IsEmpty())) {
    // The originAttributes should be default originAttributes when the
    // aClearAll flag is set.
    return NS_ERROR_INVALID_ARG;
  }

  RefPtr<Request> request = new Request(aPrincipal);

  ClearOriginParams params;

  nsresult rv = CheckedPrincipalToPrincipalInfo(aPrincipal,
                                                params.principalInfo());
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  Nullable<PersistenceType> persistenceType;
  rv = NullablePersistenceTypeFromText(aPersistenceType, &persistenceType);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return NS_ERROR_INVALID_ARG;
  }

  if (persistenceType.IsNull()) {
    params.persistenceTypeIsExplicit() = false;
  } else {
    params.persistenceType() = persistenceType.Value();
    params.persistenceTypeIsExplicit() = true;
  }

  params.clearAll() = aClearAll;

  nsAutoPtr<PendingRequestInfo> info(new RequestInfo(request, params));

  rv = InitiateRequest(info);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return rv;
  }

  request.forget(_retval);
  return NS_OK;
}
Example #20
0
bool
Animation::IsFinished() const
{
  // Unfortunately there's some weirdness in the spec at the moment where if
  // you're finished and paused, the playState is paused. This prevents us
  // from just checking |PlayState() == AnimationPlayState::Finished| here,
  // and we need this much more messy check to see if we're finished.
  Nullable<TimeDuration> currentTime = GetCurrentTime();
  return !currentTime.IsNull() &&
      ((mPlaybackRate > 0.0 && currentTime.Value() >= EffectEnd()) ||
       (mPlaybackRate < 0.0 && currentTime.Value().ToMilliseconds() <= 0.0));
}
Example #21
0
void TestDatabase::Test2() {
	cout << __PRETTY_FUNCTION__ << endl;

	bool wasCaught = false;
	try {
		Database db("localhost", "root", "", "sakila", 0, NULL, 0);
		db.Connect();

		UTASSERT(db.IsConnected());	

		Statement stmt(db, "SELECT * from COUNTRY");
		stmt.Execute();

		int testId = 0;
		std::string lastCountry;
		
		while (stmt.FetchNextRow()) {
			testId++;
			Nullable<unsigned short int> countryId = stmt.GetUShortDataInRow(0);
			Nullable<std::string> countryName = stmt.GetStringDataInRow(1);
			Nullable<Julian> lastUpdate = stmt.GetTimeDataInRow(2);

			UTASSERT(testId == (*countryId));	

			GregorianBreakdown gb = lastUpdate->to_gregorian(0);
			UTASSERT(gb.year == 2006);
			UTASSERT(gb.month == 2);
			UTASSERT(gb.day == 15);
			
			if (testId > 1) {
				UTASSERT(countryName.deref() > lastCountry);
			}
			lastCountry = countryName.deref();
		}

		UTASSERT(testId == 109);

	} catch (const DatabaseException &de) {
		cout << de << endl;
		wasCaught = true;
	} catch (const UTFail &fail) {
		throw;
	} catch (const JulianException &je) {
		cout << je.what() << endl;
		wasCaught = true;
	} catch (...) { 
		cout << "random exception caught" << endl;
		wasCaught = true;
	}

	UTASSERT(! wasCaught);	
}
Example #22
0
int main(int argc, char **argv)
{
    ros::init(argc, argv, "trolley");

    boost::thread spin_thread(&spinThread);

	ros::NodeHandle nh;
	ros::Publisher ledPublisher = nh.advertise<kinect_motor::LED>("led", 10);
	ros::Publisher motor = nh.advertise<kinect_motor::angle>("angle", 10);

	cout << "Start" << endl;

	// Prostredi.
	Environment * environment = new Environment();
	// Nacteni prostredi ze souboru.
	environment->Load("configuration.xml");

	// Rizeni pohybu robota.
	Control control(environment);

    while (ros::ok()) {

    	// Pozice osoby. NITE.
    	Nullable<XnPoint3D> userPosition = User::getInstance().UserPosition();

    	// Rizeni pohybu robota.
    	control.Position(userPosition);

		if (userPosition.HasValue()) {
			// Osoba byla detekovana.

			// Rozsvit celni diodu.
			kinect_motor::LED msg;
			msg.ledColor = 2;
			ledPublisher.publish(msg);
		}
		else {

			// Zhasni celni diodu.
			kinect_motor::LED msg;
			msg.ledColor = 0;
			ledPublisher.publish(msg);
		}
    }

    cout << "Finished" << endl;

    spin_thread.join();

    delete environment;
    return 0;
}
Example #23
0
void
Animation::SetCurrentTimeAsDouble(const Nullable<double>& aCurrentTime,
                                        ErrorResult& aRv)
{
  if (aCurrentTime.IsNull()) {
    if (!GetCurrentTime().IsNull()) {
      aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
    }
    return;
  }

  return SetCurrentTime(TimeDuration::FromMilliseconds(aCurrentTime.Value()));
}
bool HTMLElementImp::evalPxOrPercentage(HTMLElementImp* element, const std::u16string& attr, const std::u16string& prop)
{
    Nullable<std::u16string> value = element->getAttribute(attr);
    if (value.hasValue()) {
        std::u16string length = value.value();
        if (toPxOrPercentage(length)) {
            css::CSSStyleDeclaration style = element->getStyle();
            style.setProperty(prop, length, u"non-css");
            return true;
        }
    }
    return false;
}
Example #25
0
void
WebGLContext::BufferData(GLenum target,
                         const Nullable<ArrayBuffer> &maybeData,
                         GLenum usage)
{
    if (IsContextLost())
        return;

    if (maybeData.IsNull()) {
        // see http://www.khronos.org/bugzilla/show_bug.cgi?id=386
        return ErrorInvalidValue("bufferData: null object passed");
    }

    WebGLRefPtr<WebGLBuffer>* bufferSlot = GetBufferSlotByTarget(target, "bufferData");

    if (!bufferSlot) {
        return;
    }

    const ArrayBuffer& data = maybeData.Value();
    data.ComputeLengthAndData();

    // Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
    // is like intptr_t.
    if (!CheckedInt<GLsizeiptr>(data.Length()).isValid())
        return ErrorOutOfMemory("bufferData: bad size");

    if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
        return;

    WebGLBuffer* boundBuffer = bufferSlot->get();

    if (!boundBuffer)
        return ErrorInvalidOperation("bufferData: no buffer bound!");

    MakeContextCurrent();
    InvalidateBufferFetching();

    GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);

    if (error) {
        GenerateWarning("bufferData generated error %s", ErrorName(error));
        return;
    }

    boundBuffer->SetByteLength(data.Length());
    if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length())) {
        return ErrorOutOfMemory("bufferData: out of memory");
    }
}
Example #26
0
// [[Rcpp::export]]
List get_idf_cpp(List x,Nullable<CharacterVector> stop_) {

  IDFmap m;
  for(ListOf<CharacterVector>::iterator it = x.begin();it != x.end();it++){
    unsigned int dis = distance( x.begin(), it );
    auto tmp = as<CharacterVector>(*it);
    inner_find(tmp,m,dis);
  }


  
  vector<string> sts;
  vector<double> stn;
  sts.reserve(m.size());
  stn.reserve(m.size());
  
  unordered_set<string> st;

  double xsize = x.size();
  
  if(!stop_.isNull()){
    CharacterVector stop_value = stop_.get();
    const char *const stop_path = stop_value[0];
    _loadStopWordDict(stop_path,st);
    for(auto its= m.begin();its!=m.end();its++){
      if(st.find((*its).first) ==st.end()){
        sts.push_back((*its).first);
        stn.push_back( log(xsize / (*its).second.second) );
      }
    }

  }else{
    for(auto its= m.begin();its!=m.end();its++){
      sts.push_back((*its).first);
      stn.push_back((*its).second.second);
    }
  }
  
  vector<string> row_names;
  row_names.reserve(sts.size());
  for (unsigned int i = 0; i < sts.size(); ++i) {
    row_names.emplace_back(int64tos(i));
  }
  
  List res = List::create(_["name"] = wrap(sts),_["count"] = wrap(stn));
  res.attr("row.names") = row_names;
  res.attr("names") = CharacterVector::create("name","count");
  res.attr("class") = "data.frame";
  return res;
}
bool HTMLElementImp::evalVspace(HTMLElementImp* element, const std::u16string& prop)
{
    Nullable<std::u16string> value = element->getAttribute(prop);
    if (value.hasValue()) {
        std::u16string px = value.value();
        if (toPx(px)) {
            css::CSSStyleDeclaration style = element->getStyle();
            style.setProperty(u"margin-top", px, u"non-css");
            style.setProperty(u"margin-bottom", px, u"non-css");
            return true;
        }
    }
    return false;
}
bool HTMLElementImp::evalBorder(HTMLElementImp* element)
{
    Nullable<std::u16string> value = element->getAttribute(u"border");
    if (value.hasValue()) {
        std::u16string px = value.value();
        if (toPx(px)) {
            css::CSSStyleDeclaration style = element->getStyle();
            style.setProperty(u"border-width", px, u"non-css");
            style.setProperty(u"border-style", u"solid", u"non-css");
            return true;
        }
    }
    return false;
}
Example #29
0
	bool CSymbolEntry::CollectMargin(const CTradeEntry& entry)
	{
		Nullable<double> value = entry.GetMargin();
		if (!value.HasValue())
		{
			return false;
		}

		double margin = value.Value();

		if (TradeType_Position == entry.GetType())
		{
			if (TradeSide_Buy == entry.GetSide())
			{
				m_buyPositionsMargin += margin;
			}
			else
			{
				m_sellPositionsMargin += margin;
			}
		}
		else if (TradeType_Limit == entry.GetType())
		{
			if (TradeSide_Buy == entry.GetSide())
			{
				m_buyLimitOrdersMargin += margin;
			}
			else
			{
				m_sellLimitOrdersMargin += margin;
			}
		}
		else if (TradeType_Stop == entry.GetType())
		{
			if (TradeSide_Buy == entry.GetSide())
			{
				m_buyStopOrdersMargin += margin;
			}
			else
			{
				m_sellStopOrdersMargin += margin;
			}
		}
		else
		{
			throw runtime_error("CSymbolEntry::CollectMargin() unknown type");
		}
		return true;
	}
Example #30
0
bool
EventTarget::ComputeWantsUntrusted(const Nullable<bool>& aWantsUntrusted,
                                   ErrorResult& aRv)
{
  if (!aWantsUntrusted.IsNull()) {
    return aWantsUntrusted.Value();
  }

  bool defaultWantsUntrusted = ComputeDefaultWantsUntrusted(aRv);
  if (aRv.Failed()) {
    return false;
  }

  return defaultWantsUntrusted;
}