How to refactor Android libCore into Elastos libCore

Introduction



Directory Stucture ElastosRDKforUbuntu | |-+Sources |  | |   |-+Elastos |  |   |-+Browser |  |   |-+Framework |  |   |-+LibCore |  |   |   |-+car |  |   |   |-+inc |  |   |   |-+src |  |   |   |-+tests |  |   |   |--dirs |  |   |  |   |   |-+Packages
 * Elastos libCore include four directories:car,inc,src and tests.
 * Car directory and files
 * ~/ElastosRDKforUbuntu/Sources/Elastos/LibCore/car

|-+Com |-+Droid |-+Elastos |  |-+Core |  |-+IO |  |   |--IFile.car |  |   |--*.car |  |-+Lang |  |-+*   |-+*
 * -+car
 * Inc directory and files
 * ~/ElastosRDKforUbuntu/Sources/Elastos/LibCore/inc

|-+Com |-+Droid |-+Elastos |  |-+Core |  |-+IO |  |   |--CFile.h   |   |   |--File.h   |   |   |--*.h   |   |-+* |-+*
 * -+inc
 * Src directory and files
 * ~/ElastosRDKforUbuntu/Sources/Elastos/LibCore/src

|-+Com |-+Droid |-+Elastos |  |-+Core |  |-+IO |  |   |--CFile.cpp |  |   |--File.cpp |  |   |--Elastos.IO.car |  |   |--sources |  |   |--*.cpp |  |-+*   |-+*
 * -+src
 * Tests directory and files
 * ~/ElastosRDKforUbuntu/Sources/Elastos/LibCore/tests

|-+IO |  |--CFile |  |   |--test.cpp |  |   |--sources |  |-+*    |-+*
 * -+tests

Refactoring

File.java public class File implements Serializable, Comparable {

public File(File dir, String name) { java implement statements; }

public File(String path) { java implement statements; }

public File(String dirPath, String name) { java implement statements; }

public File(URI uri) { java implement statements; }

public boolean createNewFile throws IOException { java implement statements; }

public boolean isFile { java implement statements; } }

IFile.car module {   interface IFile { CreateNewFile(           [out] Boolean* succeeded);

IsFile(           [out] Boolean* isFile); } }

Elastos.IO.car module {   importlib("Elastos.Core.eco");

merge("../../../car/Elastos/IO/IFile.car");

class CFile { constructor(           [in] IFile* dir,            [in] String name);

constructor(           [in] String path);

constructor(           [in] String dirPath,            [in] String name);

constructor(           [in] IURI* uri);

interface IFile; } }

sources file for Elastos.IO.car TARGET_NAME= Elastos.IO TARGET_TYPE= eco

INCLUDES += $(MAKEDIR)/../../../inc/Elastos/common; INCLUDES += $(MAKEDIR)/../../../inc/Elastos/IO;

IMPORTS = Elastos.Core.eco IMPORTS += Elastos.Utility.eco IMPORTS += Com.Kortide.Platform.eco

SOURCES += File.cpp SOURCES += CFile.cpp

LIBRARIES = $(XDK_USER_LIB)/Elastos.Runtime.lib LIBRARIES += $(XDK_USER_LIB)/Elastos.Utility.lib LIBRARIES += $(XDK_USER_LIB)/Elastos.Core.lib ifeq "$(XDK_TARGET_PLATFORM)" "win32" LIBRARIES += $(XDK_LIB_PATH)/Elastos.Runtime.lib else LIBRARIES += $(XDK_TARGETS)/Elastos.Runtime.eco LIBRARIES += $(XDK_TARGETS)/Elastos.Utility.eco LIBRARIES += $(XDK_USER_LIB)/crt0.lib endif

File.h
 * 1) ifndef __FILE_H__
 * 2) define __FILE_H__


 * 1) include 
 * 2) include 
 * 3) include "Elastos.IO_server.h"
 * 4) include 
 * 5) ifdef _linux
 * 6) include 
 * 7) endif

using namespace Elastos;

class File { public: File;

virtual ~File;

virtual CARAPI_(PInterface) Probe(       /* [in] */ REIID riid) = 0;

CARAPI Init(       /* [in] */ IFile* dir,        /* [in] */ const String& name);

CARAPI Init(       /* [in] */ const String& path);

CARAPI Init(       /* [in] */ const String& dirPath,        /* [in] */ const String& name);

CARAPI Init(       /* [in] */ IURI* uri);

virtual CARAPI CreateNewFile(       /* [out] */ Boolean* succeeded);

virtual CARAPI IsFile(       /* [out] */ Boolean* isFile);

public: static const Char32 separatorChar; static const String separator; static const Char32 pathSeparatorChar; static const String pathSeparator;

private: const static Int64 serialVersionUID; String mPath; }

File.cpp File::File {}

File::~File {}

ECode File::Init(   /* [in] */ IFile* dir,    /* [in] */ const String& name) {       car implement statements; }

ECode File::Init(   /* [in] */ const String& path) {       car implement statements; }

ECode File::Init(   /* [in] */ const String& dirPath,    /* [in] */ const String& name) {       car implement statements; }

ECode File::Init(   /* [in] */ IURI* uri) {       car implement statements; }

ECode File::_Init(   /* [in] */ const String& dirtyPath) {       car implement statements; }

ECode File::CreateNewFile(   /* [out] */ Boolean* succeeded) {       car implement statements; }

ECode File::IsFile(   /* [out] */ Boolean* isFile) {       car implement statements; }

CFile.h
 * 1) ifndef __CFILE_H__
 * 2) define __CFILE_H__


 * 1) include "_CFile.h"
 * 2) include "File.h"

CarClass(CFile), public File { public: CARAPI_(PInterface) Probe(       /* [in] */ REIID riid);

CARAPI CreateNewFile(       /* [out] */ Boolean* succeeded);

CARAPI IsFile(       /* [out] */ Boolean* isFile);

CARAPI constructor(       /* [in] */ IFile* dir,        /* [in] */ const String& name);

CARAPI constructor(       /* [in] */ const String& path);

CARAPI constructor(       /* [in] */ const String& dirPath,        /* [in] */ const String& name);

CARAPI constructor(       /* [in] */ IURI* uri);

private: // TODO: Add your private member variables here. };


 * 1) endif // __CFILE_H__

CFile.cpp
 * 1) include "cmdef.h"
 * 2) include "CFile.h"

PInterface CFile::Probe(   /* [in] */ REIID riid) {   return _CFile::Probe(riid); }

ECode CFile::CreateNewFile(   /* [out] */ Boolean* succeeded) {   VALIDATE_NOT_NULL(succeeded);

return File::CreateNewFile(succeeded); }

ECode CFile::IsFile(   /* [out] */ Boolean* isFile) {   VALIDATE_NOT_NULL(isFile);

return File::IsFile(isFile); }

ECode CFile::constructor(   /* [in] */ IFile* dir,    /* [in] */ const String& name) {   VALIDATE_NOT_NULL(dir);

return File::Init(dir, name); }

ECode CFile::constructor(   /* [in] */ const String& path) {   return File::Init(path); }

ECode CFile::constructor(   /* [in] */ const String& dirPath,    /* [in] */ const String& name) {   return File::Init(dirPath, name); }

ECode CFile::constructor(   /* [in] */ IURI* uri) {   return File::Init(uri); }

sources file for CFile.cpp TARGET_NAME = testCFile TARGET_TYPE = ecx

IMPORTS = Elastos.IO.eco

SOURCES = test.cpp

LIBRARIES = $(XDK_USER_LIB)/Elastos.Runtime.lib ifeq "$(XDK_TARGET_PLATFORM)" "win32" LIBRARIES += $(XDK_LIB_PATH)/Elastos.Runtime.lib else LIBRARIES += $(XDK_TARGETS)/Elastos.Runtime.eco LIBRARIES += -lstdc++ endif

test.cpp
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include "Elastos.IO2.h"

using namespace Elastos;

int main(int argc, char *argv[]) {   printf("==== File: %s, Line: %d ====\n", __FILE__, __LINE__); String fp = String("/data/data/com.elastos.runtime/elastos/filetest.txt"); AutoPtr file; CFile::New(fp, (IFile**)&file); printf("==== File: %s, Line: %d ====\n", __FILE__, __LINE__); Boolean succeeded; file->CreateNewFile(&succeeded); assert(succeeded == TRUE); printf("==== File: %s, Line: %d ====\n", __FILE__, __LINE__); Boolean isfile; file->IsFile(&isfile); printf("==== File: %s, Line: %d ====\n", __FILE__, __LINE__); return 0; }

sources file of test.cpp TARGET_NAME = testCFile TARGET_TYPE = ecx

IMPORTS = Elastos.IO.eco

SOURCES = test.cpp

LIBRARIES = $(XDK_USER_LIB)/Elastos.Runtime.lib ifeq "$(XDK_TARGET_PLATFORM)" "win32" LIBRARIES += $(XDK_LIB_PATH)/Elastos.Runtime.lib else LIBRARIES += $(XDK_TARGETS)/Elastos.Runtime.eco LIBRARIES += -lstdc++ endif Code List

Building

Deploying

Back