Added implementation for desktop platform. For future use by status-react-desktop

This commit is contained in:
Volodymyr Kozieiev 2017-12-18 12:17:39 +02:00
parent cc3dc8850c
commit 534a7011ab
No known key found for this signature in database
GPG Key ID: 1F706640AAF07516
3 changed files with 103 additions and 0 deletions

7
CMakeLists.txt Normal file
View File

@ -0,0 +1,7 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_TYPE_NAMES}
\"RNRandomBytes\" PARENT_SCOPE)
set(REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC ${REACT_NATIVE_DESKTOP_EXTERNAL_MODULES_SRC}
${CMAKE_CURRENT_SOURCE_DIR}/rnrandombytesdesktop.cpp PARENT__SCOPE)

51
rnrandombytesdesktop.cpp Normal file
View File

@ -0,0 +1,51 @@
/**
* Copyright (C) 2016, Canonical Ltd.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* Author: Justin McPherson <justin.mcpherson@canonical.com>
*
*/
#include <memory>
#include "bridge.h"
#include "rnrandombytes.h"
#include <QCryptographicHash>
#include <QDateTime>
#include <QMap>
#include <QNetworkDiskCache>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QQuickImageProvider>
class RNRandomBytesPrivate {
public:
RNRandomBytesPrivate() {
qsrand(QDateTime::currentDateTime().currentMSecsSinceEpoch());
while (seed.size() < 4096) {
seed.append(QChar(qrand()));
}
}
QString seed;
};
RNRandomBytes::RNRandomBytes(QObject* parent) : QObject(parent), d_ptr(new RNRandomBytesPrivate) {}
RNRandomBytes::~RNRandomBytes() {}
QString RNRandomBytes::moduleName() {
return "RNRandomBytes";
}
QList<ModuleMethod*> RNRandomBytes::methodsToExport() {
return QList<ModuleMethod*>{};
}
QVariantMap RNRandomBytes::constantsToExport() {
return QVariantMap{{"seed", d_ptr->seed}};
}

45
rnrandombytesdesktop.h Normal file
View File

@ -0,0 +1,45 @@
/**
* Copyright (C) 2016, Canonical Ltd.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* Author: Justin McPherson <justin.mcpherson@canonical.com>
*
*/
#ifndef RNRANDOMBYTES_H
#define RNRANDOMBYTES_H
#include <QUrl>
#include "moduleinterface.h"
class RNRandomBytesPrivate;
class RNRandomBytes : public QObject, public ModuleInterface {
Q_OBJECT
Q_INTERFACES(ModuleInterface)
Q_DECLARE_PRIVATE(RNRandomBytes)
public:
enum Event { Event_LoadStart, Event_Progress, Event_LoadError, Event_LoadSuccess, Event_LoadEnd };
typedef std::function<void(Event, const QVariantMap&)> LoadEventCallback;
RNRandomBytes(QObject* parent = 0);
~RNRandomBytes();
QString moduleName() override;
QList<ModuleMethod*> methodsToExport() override;
QVariantMap constantsToExport() override;
private:
QScopedPointer<RNRandomBytesPrivate> d_ptr;
};
#endif // RNRANDOMBYTES_H