Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ThreeOneOne' into ThreeOneOne
Browse files Browse the repository at this point in the history
  • Loading branch information
grigaci committed Sep 11, 2012
2 parents 06c6fe3 + f33479a commit 45f71e9
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 57 deletions.
2 changes: 2 additions & 0 deletions runtimes/cpp/base/Syscall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ namespace Base {
#if !defined(_android)
int Syscall::maBtGetNewDevice(MABtDevice* dst) {
MABtDeviceNative dn;
dn.nameBufSize = dst->nameBufSize;
dn.name = (char*)GetValidatedMemRange(dst->name, dst->nameBufSize);
int res = BLUETOOTH(maBtGetNewDevice)(&dn);
dst->actualNameLength = dn.actualNameLength;
Expand All @@ -999,6 +1000,7 @@ namespace Base {
if(res <= 0)
return res;
MABtServiceNative sn;
sn.nameBufSize = dst->nameBufSize;
sn.name = (char*)GetValidatedMemRange(dst->name, dst->nameBufSize);
sn.uuids = (MAUUID*)GetValidatedMemRange(dst->uuids, ss.nUuids * sizeof(MAUUID));
res = BLUETOOTH(maBtGetNewService)(&sn);
Expand Down
89 changes: 38 additions & 51 deletions runtimes/cpp/base/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ class ConnOp : public Runnable {
ConnOp(MAConn& m) : mac(m) {}
MAConn& mac;

void handleResult(int opcode, int result) {
void handleResult(int opcode, int result, bool lock = true) {
LOGST("ConnOp::handleResult %i %i %i", mac.handle, opcode, result);
if(result < 0 && mac.cancel) {
if(lock)
{
gConnMutex.lock();
}
if(result < 0 && mac.cancel) {
result = CONNERR_CANCELED;
}
DEBUG_ASSERT(mac.state & opcode);
Expand All @@ -145,6 +149,10 @@ class ConnOp : public Runnable {
mac.state &= ~opcode;

ConnPushEvent(ep); //send event to be processed
if(lock)
{
gConnMutex.unlock();
}
}
};

Expand All @@ -160,11 +168,7 @@ class Connect : public ConnStreamOp {
Connect(MAStreamConn& m) : ConnStreamOp(m) {}
void run() {
LOGST("Connect %i", mac.handle);
gConnMutex.lock();
{
handleResult(CONNOP_CONNECT, masc.conn->connect());
}
gConnMutex.unlock();
handleResult(CONNOP_CONNECT, masc.conn->connect());
}
};

Expand All @@ -173,11 +177,7 @@ class ConnRead : public ConnStreamOp {
ConnRead(MAStreamConn& m, void* d, int s) : ConnStreamOp(m), dst(d), size(s) {}
void run() {
LOGST("ConnRead %i", mac.handle);
gConnMutex.lock();
{
handleResult(CONNOP_READ, masc.conn->read(dst, size));
}
gConnMutex.unlock();
handleResult(CONNOP_READ, masc.conn->read(dst, size));
}
private:
void* dst;
Expand All @@ -189,11 +189,7 @@ class ConnWrite : public ConnStreamOp {
ConnWrite(MAStreamConn& m, const void* sr, int si) : ConnStreamOp(m), src(sr), size(si) {}
void run() {
LOGST("ConnWrite %i", mac.handle);
gConnMutex.lock();
{
handleResult(CONNOP_WRITE, masc.conn->write(src, size));
}
gConnMutex.unlock();
handleResult(CONNOP_WRITE, masc.conn->write(src, size));
}
private:
const void* src;
Expand All @@ -206,13 +202,12 @@ class ConnReadToData : public ConnStreamOp {
: ConnStreamOp(m), dst(d), handle(h), offset(o), size(s) {}
void run() {
LOGST("ConnReadToData %i", mac.handle);
int result = masc.conn->read((byte*)dst.ptr() + offset, size);
gConnMutex.lock();
{
int result = masc.conn->read((byte*)dst.ptr() + offset, size);

DefluxBinPushEvent(handle, dst);

handleResult(CONNOP_READ, result);
handleResult(CONNOP_READ, result, false);
}
gConnMutex.unlock();

Expand All @@ -230,24 +225,24 @@ class ConnWriteFromData : public ConnStreamOp {
: ConnStreamOp(m), src(sr), handle(h), offset(o), size(si) {}
void run() {
LOGST("ConnWriteFromData %i", mac.handle);
gConnMutex.lock();
{
int result;
if(src.ptrc() != NULL) {
result = masc.conn->write((byte*)src.ptrc() + offset, size);

int result;
if(src.ptrc() != NULL) {
result = masc.conn->write((byte*)src.ptrc() + offset, size);
} else {
Smartie<byte> temp(new byte[size]);
if(!src.read(temp(), size)) {
LOG("Stream error in ConnWriteFromData!\n");
result = CONNERR_GENERIC;
} else {
Smartie<byte> temp(new byte[size]);
if(!src.read(temp(), size)) {
LOG("Stream error in ConnWriteFromData!\n");
result = CONNERR_GENERIC;
} else {
result = masc.conn->write(temp(), size);
}
result = masc.conn->write(temp(), size);
}

}
gConnMutex.lock();
{
DefluxBinPushEvent(handle, src);

handleResult(CONNOP_WRITE, result);
handleResult(CONNOP_WRITE, result, false);
}
gConnMutex.unlock();

Expand All @@ -264,11 +259,7 @@ class HttpFinish : public ConnOp {
HttpFinish(MAConn& m, HttpConnection& h) : ConnOp(m), http(h) {}
void run() {
LOGST("HttpFinish %i", mac.handle);
gConnMutex.lock();
{
handleResult(CONNOP_FINISH, http.finish());
}
gConnMutex.unlock();
handleResult(CONNOP_FINISH, http.finish());
}
private:
HttpConnection& http;
Expand All @@ -280,20 +271,16 @@ class Accept : public ConnOp {
void run() {
LOGST("Accept %i\n", mac.handle);
BtSppConnection* conn;
gConnMutex.lock();
{
int res = masc.serv->accept(conn);
if(res < 0) {
handleResult(CONNOP_ACCEPT, res);

return;
}
int res = masc.serv->accept(conn);
if(res < 0) {
handleResult(CONNOP_ACCEPT, res);
return;
}
//success. let's store our new connection.
MAConn* newMac = new MAStreamConn(gConnNextHandle, conn);
gConnections.insert(ConnPair(gConnNextHandle, newMac));
handleResult(CONNOP_ACCEPT, gConnNextHandle++);
}
gConnMutex.unlock();
MAConn* newMac = new MAStreamConn(gConnNextHandle, conn);
gConnections.insert(ConnPair(gConnNextHandle, newMac));
handleResult(CONNOP_ACCEPT, gConnNextHandle++);
}
private:
MAServerConn& masc;
Expand Down
17 changes: 17 additions & 0 deletions testPrograms/ParallelDownloader/.cproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>

<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="org.eclipse.cdt.core.default.config.299418359">
<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.299418359" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
<externalSettings/>
<extensions/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
<pathentry kind="con" path="com.mobilesorcery.mosync.includepaths"/>
</storageModule>
</cproject>
16 changes: 16 additions & 0 deletions testPrograms/ParallelDownloader/.mosyncproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project supports-build-configs="true" version="1.4">
<build.cfg id="Debug" types="Debug"/>
<build.cfg id="Release" types="Release"/>
<criteria>
<filter type="com.mobilesorcery.sdk.capabilities.devices.elementfactory">
<capabilities optional="" required=""/>
</filter>
</criteria>
<properties>
<property key="build.prefs:additional.libraries" value="MAUtil.lib"/>
<property key="build.prefs:additional.libraries/Debug" value="MAUtilD.lib"/>
<property key="profile.mgr.type" value="0"/>
<property key="template.id" value="project.moblet"/>
</properties>
</project>
30 changes: 30 additions & 0 deletions testPrograms/ParallelDownloader/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ParallelDownloader</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.mobilesorcery.sdk.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.mobilesorcery.sdk.core.nature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
</natures>
<filteredResources>
<filter>
<id>0</id>
<name></name>
<type>6</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-true-.*rebuild.build.cpp</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Wed Aug 15 15:13:56 CEST 2012
eclipse.preferences.version=1
encoding/<project>=UTF-8
88 changes: 88 additions & 0 deletions testPrograms/ParallelDownloader/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <ma.h>
#include <MAUtil/String.h>
#include <MAUtil/Moblet.h>
#include <conprint.h>
#include <maapi.h>

using namespace MAUtil;

#include "webImageDownloader.h"
/*
* 8 is the limit of consecutive downloads for Symbian,
* other platforms can do better.
* 32 is the limit on iOS.
*/
#define NUM_DOWNLOADS 8
#define NUM_BATCHES 10

/**
* Moblet for the application.
*/
class myMoblet : public Moblet, public webImageDownloaderListener {
public:
myMoblet()
{
mBatchNumber = 0;

printf("Number of parallel downloads:%d, number of batches:%d", NUM_DOWNLOADS, NUM_BATCHES);
startDownloads();


}

void startDownloads()
{
mFinishedDownloaders = 0;
MAUtil::String url = "http://www.mosync.com/miles/Web%20Scottish%20Loch.jpg";
mBatchNumber++;
printf("STARTING DOWNLOAD BATCH %d", mBatchNumber);
for(int i = 0; i < NUM_DOWNLOADS; i++)
{
webImageDownloader * imagedownload = new webImageDownloader(url, "newdataname1", this);
}
}

void downloadFinished(webImageDownloader *downloader)
{
delete downloader;
mFinishedDownloaders++;

if(mFinishedDownloaders == NUM_DOWNLOADS)
{
if(mBatchNumber < NUM_BATCHES)
{
startDownloads();
}
else
{
printf("TEST PASSED");
}
}
}

void myMoblet::init() {}
void myMoblet::draw() {}

/**
* Destructor.
*/
virtual ~myMoblet(){}

private:
int mFinishedDownloaders;
int mBatchNumber;
};

extern "C" int MAMain()
{
InitConsole();
gConsoleLogging = 1;

// Run the moblet event loop.
//Moblet::run(moblet);
Moblet::run(new myMoblet());

// Deallocate objects.
//delete Moblet;
return 0;
}
41 changes: 41 additions & 0 deletions testPrograms/ParallelDownloader/webImageDownloader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "webImageDownloader.h"

webImageDownloader::webImageDownloader(MAUtil::String data, MAUtil::String dataId, webImageDownloaderListener *listener){
imageDownloader = new Downloader();
imageDownloader->addDownloadListener(this);
mWebListener = listener;
mImageResource = maCreatePlaceholder();
printf("Placeholder:%d",mImageResource);
imageDownloader->beginDownloading(data.c_str(), mImageResource);
}

webImageDownloader::~webImageDownloader(){}

void webImageDownloader::finishedDownloading(Downloader *dl, MAHandle data){
printf("finished downloading");

if(dl == imageDownloader) {
printf("beginning");

printf("datasize = %d", maGetDataSize(data));
printf("MImage:%d data:%d", mImageResource, data);
MAHandle mystore = maOpenStore("teststore.jpg", MAS_CREATE_IF_NECESSARY);
if(mystore != STERR_NONEXISTENT) {
MAHandle myData = maCreatePlaceholder();
//if(maCreateData(myData, maGetDataSize(data)) == RES_OK) {
// maWriteData(myData, text.c_str(), 0, maGetDataSize(data));
//}
int result = maWriteStore(mystore, data);
maCloseStore(mystore, 0);
maDestroyPlaceholder(myData);
}
maDestroyPlaceholder(mImageResource);
mWebListener->downloadFinished(this);
printf("end of downloader");
}
}

void webImageDownloader::error(Downloader* dl, int code) { }
//maAlert("error", "", "ok", 0, 0);}
void webImageDownloader::downloadCancelled(Downloader* dl) {}
void webImageDownloader::notifyProgress(Downloader *dl, int downloadedBytes, int totalBytes){}
Loading

0 comments on commit 45f71e9

Please sign in to comment.