Skip to content

Commit

Permalink
Cleaned up some of the code so that it works with Android (again).
Browse files Browse the repository at this point in the history
On bytes received, if it’s less than one, don’t do anything. But, if
it’s something, read it and append to the buffer. On finished, read
the rest of anything that’s in the pipe.

A little more output in the context.

Bumped the build numbers up to 2. (Now both platforms in sync.)
  • Loading branch information
Masa committed Jul 13, 2016
1 parent ef754ac commit 803a22b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
19 changes: 13 additions & 6 deletions client/FJClient/FJOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ FJOperation::FJOperation(const QString& name, const QString& checkFetch,

FJOperation::~FJOperation()
{
qDebug() << "[" << _name << "] FJOperation::~FJOperation()";
}

void
Expand Down Expand Up @@ -117,6 +116,7 @@ FJOperation::_OnAuthenticationRequired(QNetworkReply *,
void
_NetworkErrorPrintError(const QNetworkReply::NetworkError& error)
{
return;
switch(error) {
case QNetworkReply::NoError:
qDebug() << "No Error";
Expand All @@ -142,10 +142,13 @@ FJOperation::_OnReplyFinished(QNetworkAccessManagerSharedPtr accessManager,
_RunRequest(accessManager, baseUrl, opType);
} else {
_StoreCSRF(accessManager, baseUrl);
// Read the rest of the buffer, if there's anything left
_buffer.append(_reply->readAll());
QJsonDocument jsonDoc = _GetJsonFromContent(_buffer);
if (jsonDoc.isNull() || jsonDoc.isEmpty()) {
_NetworkErrorPrintError(_reply->error());
qDebug() << "Invalid JSON for " << baseUrl << ": " << _buffer;
_status = FJCompletedStatus;
} else if (opType == FJCheckOperationType) {
if (_ProcessCheck(jsonDoc)) {
_RunRequest(accessManager, baseUrl, FJFetchOperationType);
Expand All @@ -161,7 +164,6 @@ FJOperation::_OnReplyFinished(QNetworkAccessManagerSharedPtr accessManager,
_status = FJCompletedStatus;
}
}
qDebug() << "_OnReplyfinished completed";
}

void
Expand All @@ -173,8 +175,13 @@ FJOperation::_OnBytesReceived(qint64 bytesReceived, qint64 )
}
char buffer[bytesReceived+1];
qint64 bytesRead = _reply->read(buffer, bytesReceived);
if (bytesRead != bytesReceived) {
if (bytesRead == -1) {
qDebug() << "-1 returned from QIODevice::read()";
return;
} else if (bytesRead != bytesReceived) {
// This was garbage (on android, at least), so throw it out.
qDebug() << "Read " << bytesRead << ", expected " << bytesReceived;
// << "[" << buffer << "]";
}
_buffer.append(buffer);
}
Expand All @@ -193,10 +200,10 @@ void
FJOperation::_OnFinished(QNetworkAccessManagerSharedPtr accessManager,
const QUrl& baseUrl)
{
qDebug() << "Operation: OnFinished";
QObject::disconnect(_reply, 0, 0, 0);
_StoreCSRF(accessManager, baseUrl);
_buffer.append(_reply->readAll());
QByteArray rest = _reply->readAll();
_buffer.append(rest);
QJsonDocument jsonDoc = _GetJsonFromContent(_buffer);
if (!jsonDoc.isNull() and !jsonDoc.isEmpty()) {
if (_caller) {
Expand Down Expand Up @@ -252,7 +259,7 @@ FJOperation::_GetJsonFromContent(const QByteArray& content)
cleanedContent.chop(1);
desiredSize--;
}
//qDebug() << "Trunc: <<" << _buffer.data() << ">>";
//qDebug() << "Trunc: <<" << cleanedContent << ">>";
return QJsonDocument::fromJson(cleanedContent);
}

Expand Down
10 changes: 6 additions & 4 deletions client/SFOsaka/SFOContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ SFOContext::FlushToDisk()
QJsonObject obj = QJsonObject::fromVariantMap(partnerMap);
QJsonDocument doc;
doc.setObject(obj);
qDebug() << "Saving " << _partners.size() << " partners";
_WriteCacheFile(doc, PartnerCacheFileName);
}

Expand All @@ -201,6 +202,7 @@ SFOContext::FlushToDisk()
QJsonObject obj = QJsonObject::fromVariantMap(allDicts);
QJsonDocument doc;
doc.setObject(obj);
qDebug() << "Saving " << allDicts.size() << " words";
_WriteCacheFile(doc, DictionaryCacheFileName);
}
}
Expand Down Expand Up @@ -455,12 +457,12 @@ SFOContext::_UpdateDictionaryIfNecessary()
}

void
SFOContext::HandleResponse(const QJsonDocument& document, FJError /*error*/,
SFOContext::HandleResponse(const QJsonDocument& document, FJError error,
const FJOperation* operation)
{
// qDebug() << QThread::currentThreadId() << "HandleResponse: "
// << operation->GetName() ;
// << ", (" << error << ") Doc: [" << document << "]";
qDebug() << QThread::currentThreadId() << "HandleResponse: "
<< operation->GetName()
<< ", (" << error << ") Doc: [" << document << "]";
if (operation && (operation->GetName() == "start")) {
_HandleStartResponse(document);
} else if (operation && (operation->GetName() == "partners")) {
Expand Down
7 changes: 5 additions & 2 deletions client/SFOsaka/SFOsaka.pro
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ LIBS += -L$$PWD/../build-FJClient-iphonesimulator_clang_Qt_5_6_0_for_iOS-Debug/
}
iphoneos{
LIBS += -L$$PWD/../build-FJClient-iphoneos_clang_Qt_5_6_0_for_iOS-Debug/ -lFJClient
#LIBS += -L$$PWD/../build-FJClient-iphoneos_clang_Qt_5_6_0_for_iOS-Release/ -lFJClient
}
android{
LIBS += -L$$PWD/../build-FJClient-Android_for_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/ -lFJClient
Debug:LIBS += -L$$PWD/../build-FJClient-Android_for_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/ -lFJClient
Release:LIBS += -L$$PWD/../build-FJClient-Android_for_armeabi_v7a_GCC_4_9_Qt_5_6_0-Release/ -lFJClient
}
osx{
LIBS += -L$$PWD/../build-FJClient-Desktop_Qt_5_6_0_clang_64bit-Debug/ -lFJClient
Expand All @@ -90,7 +92,8 @@ iphonesimulator {
PRE_TARGETDEPS += $$PWD/../build-FJClient-iphonesimulator_clang_Qt_5_6_0_for_iOS-Debug/libFJClient.a
}
iphoneos{
PRE_TARGETDEPS += $$PWD/../build-FJClient-iphoneos_clang_Qt_5_6_0_for_iOS-Debug/libFJClient.a
Debug:PRE_TARGETDEPS += $$PWD/../build-FJClient-iphoneos_clang_Qt_5_6_0_for_iOS-Debug/libFJClient.a
Release:PRE_TARGETDEPS += $$PWD/../build-FJClient-iphoneos_clang_Qt_5_6_0_for_iOS-Release/libFJClienta.
}
android{
Debug:PRE_TARGETDEPS += $$PWD/../build-FJClient-Android_for_armeabi_v7a_GCC_4_9_Qt_5_6_0-Debug/libFJClient.a
Expand Down
2 changes: 1 addition & 1 deletion client/SFOsaka/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<manifest package="net.futomen.SFOsaka" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<manifest package="net.futomen.SFOsaka" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="2.0" android:versionCode="2" android:installLocation="auto">
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:icon="@drawable/icon">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="-- %%INSERT_APP_NAME%% --" android:screenOrientation="unspecified" android:launchMode="singleTop">
<intent-filter>
Expand Down
6 changes: 3 additions & 3 deletions client/SFOsaka/ios/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>SFOsaka</string>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>SFOsaka</string>
<key>CFBundleGetInfoString</key>
Expand All @@ -29,7 +29,7 @@
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>net.futomen.${PRODUCT_NAME}</string>
<string>net.futomen.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
Expand All @@ -39,7 +39,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>2.0</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
Expand Down

0 comments on commit 803a22b

Please sign in to comment.