예제 #1
0
void KaaClient::syncTopicSubscriptions() {
#ifdef KAA_USE_NOTIFICATIONS
    notificationManager_->sync();
#else
    throw KaaException("Failed to get synchronized . Notification subsystem is disabled");
#endif
}
예제 #2
0
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
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
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
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
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
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
Topics KaaClient::getTopics() {
#ifdef KAA_USE_NOTIFICATIONS
    return notificationManager_->getTopics();
#else
    throw KaaException("Failed to get topics. Notification subsystem is disabled");
#endif
}
예제 #9
0
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
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
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
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
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
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
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
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
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
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
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
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
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
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::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());
}