Skip to content

Commit

Permalink
Merge pull request #12 from MozCloudStorage/readfile
Browse files Browse the repository at this point in the history
Implement file reading feature.
  • Loading branch information
weilonge committed Jun 5, 2015
2 parents 723d0fb + 95478d4 commit 886b31b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
48 changes: 24 additions & 24 deletions dom/system/gonk/cloudstorage/CloudStorageRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <dirent.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/uio.h>
Expand All @@ -43,7 +43,7 @@ class CloudStorageRequestRunnable : public nsRunnable
}

nsresult Run()
{
{
nsresult rv;
// if (!mInterface) {
nsCOMPtr<nsICloudStorageInterface > mInterface = do_CreateInstance("@mozilla.org/cloudstorageinterface;1", &rv);
Expand Down Expand Up @@ -142,7 +142,7 @@ CloudStorageRequestHandler::Init()
mFuseHandler = new FuseHandler();
mFuseHandler->fuse = mFuse;
mFuseHandler->token = 0;

umask(0);
}

Expand Down Expand Up @@ -376,7 +376,7 @@ CloudStorageRequestHandler::HandleLookup(const FuseInHeader *hdr, const char* na
LOG("Lookup");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s, passed name %s", path.get(), name);
nsCString childpath = path;
Expand All @@ -389,7 +389,7 @@ CloudStorageRequestHandler::HandleLookup(const FuseInHeader *hdr, const char* na
if (childnid == 0) {
return -ENOMEM;
}

FuseEntryOut out;
out.attr.ino = hdr->nodeid;
out.attr = mCloudStorage->GetAttrByPath(childpath);
Expand Down Expand Up @@ -430,19 +430,19 @@ CloudStorageRequestHandler::HandleLookup(const FuseInHeader *hdr, const char* na
}

int
CloudStorageRequestHandler::HandleForget(const FuseInHeader *hdr, const FuseForgetIn *req)
CloudStorageRequestHandler::HandleForget(const FuseInHeader *hdr, const FuseForgetIn *req)
{
LOG("Forget");
return CLOUD_STORAGE_NO_STATUS;
}

int
CloudStorageRequestHandler::HandleGetAttr(const FuseInHeader *hdr, const FuseGetAttrIn* req)
CloudStorageRequestHandler::HandleGetAttr(const FuseInHeader *hdr, const FuseGetAttrIn* req)
{
LOG("GetAttr");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s", path.get());

Expand Down Expand Up @@ -528,7 +528,7 @@ CloudStorageRequestHandler::HandleOpen(const FuseInHeader* hdr, const FuseOpenIn
LOG("Open");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s", path.get());

Expand All @@ -538,8 +538,8 @@ CloudStorageRequestHandler::HandleOpen(const FuseInHeader* hdr, const FuseOpenIn
out.open_flags = 0;
out.padding = 0;

CloudStorageTester tester;
tester.Open(path, out.fh);
//CloudStorageTester tester;
//tester.Open(path, out.fh);

if (mCloudStorage->State() == CloudStorage::STATE_RUNNING) {
FuseOutHeader outhdr;
Expand All @@ -566,24 +566,24 @@ CloudStorageRequestHandler::HandleRead(const FuseInHeader* hdr, const FuseReadIn
LOG("Read");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s, nodeid: %llu, size: %d, offset: %d", path.get(), hdr->nodeid, req->size, (int)req->offset);

char* buffer = (char*)malloc(sizeof(char)*req->size);
int32_t size = -1;

CloudStorageTester tester;
tester.GetData(req->fh, req->size, req->offset, buffer, size);
//CloudStorageTester tester;
//tester.GetData(req->fh, req->size, req->offset, buffer, size);

CloudStorageRequestData reqData;
reqData.RequestType = (uint32_t) FUSE_READ;
reqData.Path = path;
reqData.Size = req->size;
reqData.Offset = req->offset;
mCloudStorage->SetRequestData(reqData);
SendRequestToMainThread();


if (mCloudStorage->State() == CloudStorage::STATE_RUNNING) {
if (size < 0) {
Expand Down Expand Up @@ -628,12 +628,12 @@ CloudStorageRequestHandler::HandleRelease(const FuseInHeader* hdr, const FuseRel
LOG("Release");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s", path.get());

CloudStorageTester tester;
tester.Close(req->fh);
//CloudStorageTester tester;
//tester.Close(req->fh);
return 0;
}

Expand All @@ -651,7 +651,7 @@ CloudStorageRequestHandler::HandleFlush(const FuseInHeader* hdr)

nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s", path.get());

Expand All @@ -666,7 +666,7 @@ CloudStorageRequestHandler::HandleOpenDir(const FuseInHeader* hdr, const FuseOpe

nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s", path.get());
FuseOpenOut out;
Expand Down Expand Up @@ -701,15 +701,15 @@ CloudStorageRequestHandler::HandleReadDir(const FuseInHeader* hdr, const FuseRea
LOG("ReadDir");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s, offset: %llu", path.get(), req->offset);
char buffer[8192];
FuseDirent *fde = (FuseDirent*) buffer;
fde->ino = FUSE_UNKNOWN_INO;
fde->off = req->offset + 1;
nsCString entryName;

entryName = mCloudStorage->GetEntryByPathAndOffset(path, req->offset);
if (entryName.Equals(NS_LITERAL_CSTRING(""))) {
CloudStorageRequestData reqData;
Expand Down Expand Up @@ -765,7 +765,7 @@ CloudStorageRequestHandler::HandleReleaseDir(const FuseInHeader* hdr, const Fuse
LOG("ReleaseDir");
nsCString path = mCloudStorage->GetPathByNId(hdr->nodeid);
if (path.Equals(NS_LITERAL_CSTRING(""))) {
return -ENOENT;
return -ENOENT;
}
LOG("path: %s", path.get());
uint64_t* handle = (uint64_t*)(uintptr_t) req->fh;
Expand Down
5 changes: 5 additions & 0 deletions dom/system/gonk/cloudstorage/foco.jsm
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
this.EXPORTED_SYMBOLS = ['foco'];
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
XPCOMUtils.defineLazyModuleGetter(this, 'setTimeout',
'resource://gre/modules/Timer.jsm');

var self = this;
(function (){
var foco = {};
Expand Down
6 changes: 3 additions & 3 deletions dom/system/gonk/cloudstorage/nsCloudStorageInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function log(msg) {
dump('CloudStorage: ' + msg + '\n');
}

function nsCloudStorageInterface() {
function nsCloudStorageInterface() {
log("nsCloudStorageInterface constructor");
log("call udManager.init()");
udManager.init({
accessToken:
'kR1EcZML0N4AAAAAAAAAR7FkWBgDSVFk17g3--pNIBv0sR_gs85HlSkHAo8q_6-N',
webStorageModule: Dropbox,
webStorageModule: Sample,
metaCacheModule: MetaCache,
dataCacheModule: DataCache
})
Expand All @@ -58,7 +58,7 @@ nsCloudStorageInterface.prototype = {
instance.finishRequest(cloudname);
});
},

getFileList: function(cloudname, path) {
log("cloudname: " + cloudname + " " + "path: " + path);
log("call udManager.getFileList");
Expand Down
5 changes: 4 additions & 1 deletion dom/system/gonk/cloudstorage/udManager.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const { classes: Cc, interfaces: Ci, utils: Cu } = Components;

Cu.import('resource://gre/modules/foco.jsm');
const { console } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
XPCOMUtils.defineLazyModuleGetter(this, 'setTimeout',
'resource://gre/modules/Timer.jsm');

var UD_BLOCK_SIZE = 1*1024*1024;
var UD_QUEUE_SIZE = 3;
Expand Down Expand Up @@ -242,7 +245,7 @@ udManager.downloadFileInRange = function(path, offset, size, cb) {
if(error){
console.log('[ERROR] retry, error happened: ' + error);
setTimeout(retry , 800);
}else if( !response || !response.data || !response.data instanceof Buffer ){
}else if( !response || !response.data || !response.data instanceof ArrayBuffer ){
console.log('[ERROR] retry, error response: ' + response);
setTimeout(retry , 800);
}else if( size != response.length ){
Expand Down

0 comments on commit 886b31b

Please sign in to comment.