コード例 #1
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::syncTopicSubscriptions() {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->sync();
#else
    throw KaaException("Failed to get synchronized . Notification subsystem is disabled");
#endif
}
コード例 #2
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::setAttachStatusListener(IAttachStatusListenerPtr listener) {
#ifdef KAA_USE_EVENTS
    return registrationManager_->setAttachStatusListener(listener);
#else
    throw KaaException("Failed to set listerner's status. Event subsystem is disabled");
#endif
}
コード例 #3
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::subscribeToTopic(const std::string& id, bool forceSync) {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->subscribeToTopic(id, forceSync);
#else
    throw KaaException("Failed to subscribe to topics. Notification subsystem is disabled");
#endif
}
コード例 #4
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::unsubscribeFromTopics(const std::list<std::string>& idList, bool forceSync) {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->unsubscribeFromTopics(idList, forceSync);
#else
    throw KaaException("Failed to unsubscribe to topics. Notification subsystem is disabled");
#endif
}
コード例 #5
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::addNotificationListener(INotificationListener& listener) {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->addNotificationListener(listener);
#else
    throw KaaException("Failed to add notification listener. Notification subsystem is disabled");
#endif
}
コード例 #6
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::removeNotificationListener(const std::string& topidId, INotificationListener& listener) {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->removeNotificationListener(topidId, listener);
#else
    throw KaaException("Failed to remove notification listener. Notification subsystem is disabled");
#endif
}
コード例 #7
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::removeTopicListListener(INotificationTopicListListener& listener) {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->removeTopicListListener(listener);
#else
    throw KaaException("Failed to remove topic list listeners. Notification subsystem is disabled");
#endif
}
コード例 #8
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
Topics KaaClient::getTopics() {
#ifdef KAA_USE_NOTIFICATIONS
    return notificationManager_->getTopics();
#else
    throw KaaException("Failed to get topics. Notification subsystem is disabled");
#endif
}
コード例 #9
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
const KaaRootConfiguration& KaaClient::getConfiguration() {
#ifdef KAA_USE_CONFIGURATION
    return configurationManager_->getConfiguration();
#else
    throw KaaException("Failed to subscribe to get configuration. Configuration subsystem is disabled");
#endif
}
コード例 #10
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::removeConfigurationListener(IConfigurationReceiver &receiver) {
#ifdef KAA_USE_CONFIGURATION
    configurationManager_->unsubscribeFromConfigurationChanges(receiver);
#else
    throw KaaException("Failed to unsubscribe from configuration changes. Configuration subsystem is disabled");
#endif
}
コード例 #11
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::setConfigurationStorage(IConfigurationStoragePtr storage) {
#ifdef KAA_USE_CONFIGURATION
    configurationPersistenceManager_->setConfigurationStorage(storage);
#else
    throw KaaException("Failed to set configuration storage. Configuration subsystem is disabled");
#endif
}
コード例 #12
0
ファイル: EventManager.cpp プロジェクト: BillTheBest/kaa
std::int32_t EventManager::findEventListeners(const std::list<std::string>& eventFQNs, IFetchEventListenersPtr listener)
{
    if (eventFQNs.empty() || !listener) {
        KAA_LOG_WARN("Failed to add event listeners request: bad input data");
        throw KaaException("Bad event listeners data");
    }

    std::int32_t requestId = UuidGenerator::generateRandomInt();

    std::shared_ptr<EventListenersInfo> info(new EventListenersInfo);
    info->eventFQNs_ = eventFQNs;
    info->listener_ = listener;

    {
        KAA_MUTEX_LOCKING("eventListenersGuard_");
        KAA_MUTEX_UNIQUE_DECLARE(eventListenersLock, eventListenersGuard_);
        KAA_MUTEX_LOCKED("eventListenersGuard_");

        eventListenersRequests_.insert(std::make_pair(requestId, info));
        KAA_MUTEX_UNLOCKED("eventListenersGuard_");
    }

    KAA_LOG_TRACE("Added event listeners resolving request");

    doSync();

    return requestId;
}
コード例 #13
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
bool KaaClient::isAttachedToUser() {
#ifdef KAA_USE_EVENTS
        return registrationManager_->isAttachedToUser();
#else
        throw KaaException("Failed to set listerner's status. Event subsystem is disabled");
#endif
}
コード例 #14
0
ファイル: CommonRecord.cpp プロジェクト: aiyi/kaa
ICommonRecord::fields_type CommonRecord::getField(const keys_type &field_name) const
{
    if (!hasField(field_name)) {
        throw KaaException(boost::format("Field with name %1% was not found in record") % field_name);
    }
    auto it = fields_.find(field_name);
    return it->second;
}
コード例 #15
0
void ConfigurationManager::addReceiver(IConfigurationReceiver &receiver)
{
    if (!configurationReceivers_.addCallback(&receiver,
            std::bind(&IConfigurationReceiver::onConfigurationUpdated,
                      &receiver, std::placeholders::_1))) {
        throw KaaException("Failed to add a configuration changes subscriber. Already subscribed");
    }
}
コード例 #16
0
ファイル: KaaClient.cpp プロジェクト: BioSoundSystems/kaa
EventFamilyFactory& KaaClient::getEventFamilyFactory()
{
#ifdef KAA_USE_EVENTS
    return *eventFamilyFactory_;
#else
    throw KaaException("Failed to retrieve EventFamilyFactory. Event subsystem is disabled");
#endif
}
コード例 #17
0
ファイル: CommonRecord.cpp プロジェクト: aiyi/kaa
void CommonRecord::removeField(const keys_type &field_name)
{
    if (!hasField(field_name)) {
        throw KaaException(boost::format("Field with name %1% was not found in record") % field_name);
    } else {
        fields_.erase(field_name);
    }
}
コード例 #18
0
ファイル: Kaa.cpp プロジェクト: nthevu/kaa
std::shared_ptr<IKaaClient> Kaa::newClient(IKaaClientPlatformContextPtr context
                                         , IKaaClientStateListenerPtr listener)
{
    if (!context) {
        throw KaaException("Kaa client platform context is null");
    }
    return std::shared_ptr<IKaaClient>(new KaaClient(context, listener));
}
コード例 #19
0
ファイル: KaaClient.cpp プロジェクト: BioSoundSystems/kaa
void KaaClient::attachUser(const std::string& userExternalId, const std::string& userAccessToken
                          , const std::string& userVerifierToken, IUserAttachCallbackPtr listener) {
#ifdef KAA_USE_EVENTS
    return registrationManager_->attachUser(userExternalId, userAccessToken, userVerifierToken, listener);
#else
    throw KaaException("Failed to attach user. Event subsystem is disabled");
#endif
}
コード例 #20
0
ファイル: KaaClient.cpp プロジェクト: BioSoundSystems/kaa
void KaaClient::detachEndpoint(const std::string&  endpointKeyHash
                              , IDetachEndpointCallbackPtr listener) {
#ifdef KAA_USE_EVENTS
    return registrationManager_->detachEndpoint(endpointKeyHash, listener);
#else
    throw KaaException("Failed to detach endpoint. Event subsystem is disabled");
#endif
}
コード例 #21
0
ファイル: KaaClient.cpp プロジェクト: BioSoundSystems/kaa
void KaaClient::attachEndpoint(const std::string&  endpointAccessToken
                              , IAttachEndpointCallbackPtr listener) {
#ifdef KAA_USE_EVENTS
    return registrationManager_->attachEndpoint(endpointAccessToken, listener);
#else
    throw KaaException("Failed to attach endpoint. Event subsystem is disabled");
#endif
}
コード例 #22
0
ファイル: EndpointObjectHash.cpp プロジェクト: Acarus/kaa
void EndpointObjectHash::calculateHash(const std::uint8_t* data, std::uint32_t dataSize)
{
    if (!data && dataSize != 0) {
        throw KaaException("empty raw data or null size");
    }
    Botan::SHA_160 sha;
    const auto& result = sha.process(data, dataSize);
    hashDigest_.assign(result.begin(), result.end());
}
コード例 #23
0
ファイル: BootstrapManager.cpp プロジェクト: xwiz/kaa
void BootstrapManager::setTransport(IBootstrapTransport* transport)
{
    KAA_R_MUTEX_UNIQUE_DECLARE(lock, guard_);
    bootstrapTransport_ = dynamic_cast<BootstrapTransport*>(transport);
    if (bootstrapTransport_ != nullptr) {
        return;
    }
    throw KaaException("Bad bootstrap transport");
}
コード例 #24
0
ファイル: LogCollector.cpp プロジェクト: xwiz/kaa
void LogCollector::setUploadStrategy(ILogUploadStrategyPtr strategy)
{
    if (!strategy) {
        KAA_LOG_ERROR("Failed to set log upload strategy: bad data");
        throw KaaException("Bad log upload strategy");
    }

    KAA_LOG_INFO("New log upload strategy was set");
    uploadStrategy_ = strategy;
}
コード例 #25
0
ファイル: KaaClient.cpp プロジェクト: howardroark2018/kaa
void KaaClient::setFailoverStrategy(IFailoverStrategyPtr strategy) {
    if (!strategy) {
        KAA_LOG_ERROR("Failed to set failover strategy: bad data");
        throw KaaException("Bad failover strategy");
    }

    KAA_LOG_INFO("New failover strategy was set");
    failoverStrategy_ = strategy;
    channelManager_->setFailoverStrategy(failoverStrategy_);
}
コード例 #26
0
ファイル: CommonRecord.cpp プロジェクト: aiyi/kaa
void CommonRecord::setField(const keys_type &field_name, fields_type value)
{
    if (hasField(field_name)) {
        fields_[field_name] = value;
    } else {
        auto res = fields_.insert(std::make_pair(field_name, value));
        if (!res.second) {
            throw KaaException(boost::format("Failed to insert field \"%1%\" into record") % field_name);
        }
    }
}
コード例 #27
0
void AvroByteArrayConverter<T>::fromByteArray(const std::uint8_t* data, const std::uint32_t& dataSize, T& datum)
{
    if ((data && !dataSize) || (dataSize && !data)) {
        throw KaaException("invalid data to decode");
    }

    std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(data, dataSize);

    decoder_->init(*in);
    avro::decode(*decoder_, datum);
}
コード例 #28
0
ファイル: ConfigurationTransport.cpp プロジェクト: nthevu/kaa
std::shared_ptr<ConfigurationSyncRequest> ConfigurationTransport::createConfigurationRequest()
{
    if (!clientStatus_ || !hashContainer_) {
        throw KaaException("Can not generate ConfigurationSyncRequest: configuration transport is not initialized");
    }

    std::shared_ptr<ConfigurationSyncRequest> request(new ConfigurationSyncRequest);
    request->appStateSeqNumber = clientStatus_->getConfigurationSequenceNumber();
    request->configurationHash.set_bytes(hashContainer_->getConfigurationHash());
    request->resyncOnly.set_bool(true); // Only full resyncs are currently supported
    return request;
}
コード例 #29
0
ファイル: KaaChannelManager.cpp プロジェクト: nthevu/kaa
void KaaChannelManager::onServerFailed(ITransportConnectionInfoPtr connectionInfo) {
    if (isShutdown_) {
        KAA_LOG_WARN("Can't update server. Channel manager is down");
        return;
    }
    if (!connectionInfo) {
        KAA_LOG_WARN("Failed to process server failure: bad input data")
        throw KaaException("empty connection info pointer");
    }

    if (connectionInfo->isFailedState()) {
        KAA_LOG_DEBUG("Connection already failed. Ignoring connection failover!");
        return;
    } else {
        connectionInfo->setFailedState();
    }

    if (connectionInfo->getServerType() == ServerType::BOOTSTRAP) {
        ITransportConnectionInfoPtr nextConnectionInfo = getNextBootstrapServer(connectionInfo->getTransportId(), false);
        if (nextConnectionInfo) {
            onTransportConnectionInfoUpdated(nextConnectionInfo);
        } else {
            FailoverStrategyDecision decision = failoverStrategy_->onFailover(Failover::BOOTSTRAP_SERVERS_NA);
            switch (decision.getAction()) {
                 case FailoverStrategyAction::NOOP:
                     KAA_LOG_WARN("No operation is performed according to failover strategy decision.");
                     break;
                 case FailoverStrategyAction::RETRY:
                 {
                     std::size_t period = decision.getRetryPeriod();
                     KAA_LOG_WARN(boost::format("Attempt to reconnect to first bootstrap server will be made in %1% secs "
                             "according to failover strategy decision.") % period);
                     bsTransportId_ = connectionInfo->getTransportId();
                     retryTimer_.stop();
                     retryTimer_.start(period, [&]
                         {
                             onTransportConnectionInfoUpdated(getNextBootstrapServer(bsTransportId_, true));
                         });
                     break;
                 }
                 case FailoverStrategyAction::STOP_APP:
                     KAA_LOG_WARN("Stopping application according to failover strategy decision!");
                     exit(EXIT_FAILURE);
                     break;
                 default:
                    break;
             }
        }
    } else {
        bootstrapManager_.useNextOperationsServer(connectionInfo->getTransportId());
    }
}
コード例 #30
0
ファイル: IPTransportInfo.cpp プロジェクト: alex1818/kaa
IPTransportInfo::IPTransportInfo(ITransportConnectionInfoPtr connectionInfo)
    : GenericTransportInfo(connectionInfo->getServerType(), ProtocolMetaData())
{
    if (!connectionInfo || connectionInfo->getConnectionInfo().empty()) {
        KAA_LOG_ERROR("Failed to create IP transport data: bad input data");
        throw KaaException("Bad connection data");
    }

    serverType_ = connectionInfo->getServerType();
    connectionData_ = connectionInfo->getConnectionInfo();
    accessPointId_ = connectionInfo->getAccessPointId();
    protocolId_ = connectionInfo->getTransportId();

    std::uint8_t *data = connectionData_.data();
    std::int32_t publicKeyLength = boost::asio::detail::socket_ops::network_to_host_long(*((int32_t *)data));
    data += sizeof(std::int32_t);

    publicKey_ = PublicKey(data, publicKeyLength);
    data += publicKeyLength;

    std::int32_t hostLength = boost::asio::detail::socket_ops::network_to_host_long(*((int32_t *)data));
    data += sizeof(std::int32_t);
    host_.assign(data, data + hostLength);
    data += hostLength;

    port_ = boost::asio::detail::socket_ops::network_to_host_long(*((int32_t *)data));

    std::ostringstream ss;
    ss << "http://" << host_ << ":" << port_;
    url_.assign(ss.str());

    if ((3 * sizeof(std::int32_t) + publicKeyLength + hostLength) > connectionData_.size()) {
        KAA_LOG_ERROR("Failed to create IP transport data: less size of input data than needed");
        throw KaaException("Bad connection data");
    }

    KAA_LOG_TRACE(boost::format("Create IP transport data: host=%1%, port=%2%, publicKeyLength=%3%") % host_% port_ % publicKey_.size());
}