From dfda992121cbe125524ac31f14142b5d6545aa2f Mon Sep 17 00:00:00 2001 From: wess Date: Sat, 30 Apr 2011 18:12:53 -0400 Subject: [PATCH] Added and started develing embedding test project, working on correct linking --- Makefile | 56 -------------- Makefile_run | 44 ----------- SConstruct | 11 ++- bak_SConstruct | 1 + blah1.txt | 1 - blah2.txt | 0 build.sh | 8 -- embed_testing/SConstruct | 42 +++++++++++ embed_testing/build/testing | Bin 0 -> 9396 bytes embed_testing/main.cpp | 8 ++ embed_testing/main.o | Bin 0 -> 2908 bytes src/core.cpp | 145 ++++++++++++++++++++++++++++++++++++ src/core.h | 3 + src/main.cpp | 4 +- test/testmodule/Makefile | 22 ------ 15 files changed, 210 insertions(+), 135 deletions(-) delete mode 100644 Makefile delete mode 100644 Makefile_run delete mode 100644 blah1.txt delete mode 100644 blah2.txt delete mode 100755 build.sh create mode 100644 embed_testing/SConstruct create mode 100755 embed_testing/build/testing create mode 100644 embed_testing/main.cpp create mode 100644 embed_testing/main.o create mode 100644 src/core.cpp delete mode 100644 test/testmodule/Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index a3adcca..0000000 --- a/Makefile +++ /dev/null @@ -1,56 +0,0 @@ -## NOTE: TO BUILD v8:: -## do: sudo su && cd /usr/local -## Checkout from: svn checkout http://v8.googlecode.com/svn/trunk/ v8 -## then (for debug) run: scons mode=debug library=shared -## once that is done, run: install_name_tool -id /usr/local/v8/libv8_g.dylib libv8_g.dylib - -SRC_DIR = src -BUILD_TARGET = build/core -V8_DIR = /usr/local/v8/libv8_g.dylib -V8_INC = /usr/local/v8/include - -SOURCES = $(SRC_DIR)/main.cpp \ - $(SRC_DIR)/System/system.cpp \ - $(SRC_DIR)/Env/env.cpp \ - $(SRC_DIR)/Directory/directory.cpp \ - $(SRC_DIR)/File/file.cpp \ - $(SRC_DIR)/Http/url.cpp \ - $(SRC_DIR)/Path/path.cpp \ - $(SRC_DIR)/Path/pathHistory.cpp \ - $(SRC_DIR)/Http/client.cpp \ - $(SRC_DIR)/Module/module.cpp \ - $(SRC_DIR)/Events/BaseEvent.cpp \ - $(SRC_DIR)/Socket/Socket.cpp \ - $(SRC_DIR)/Socket/serverSocket.cpp \ - $(SRC_DIR)/Socket/clientSocket.cpp \ - $(SRC_DIR)/Threading/threadPool.cpp - -HEADERS = -I/usr/local/include \ - -I$(V8_INC) \ - -I$(SRC_DIR) \ - -I$(SRC_DIR)/Headers \ - -I$(SRC_DIR)/System \ - -I$(SRC_DIR)/Env \ - -I$(SRC_DIR)/Directory \ - -I$(SRC_DIR)/File \ - -I$(SRC_DIR)/Path \ - -I$(SRC_DIR)/Http \ - -I$(SRC_DIR)/Module \ - -I$(SRC_DIR)/Events \ - -I$(SRC_DIR)/Socket \ - -I$(SRC_DIR)/Threading - -LIBS = $(V8_DIR) \ - /usr/local/lib/libevent_pthreads.dylib \ - -L/usr/local/lib - -TARGET = $(BUILD_TARGET) - -OBJS = $(SOURCES:.cpp=.o) -CC=g++ -CXXFLAGS= -arch i386 -Wall -lpthread -levent - -all: $(OBSJ) - $(CC) $(CXXFLAGS) $(HEADERS) $(SOURCES) -o $(TARGET) $(LIBS) -clean: - rm -rf build/* diff --git a/Makefile_run b/Makefile_run deleted file mode 100644 index b52a7f9..0000000 --- a/Makefile_run +++ /dev/null @@ -1,44 +0,0 @@ -SRC_DIR = src -## NOTE: TO BUILD v8:: -## do: sudo su && cd /usr/local -## Checkout from: svn checkout http://v8.googlecode.com/svn/trunk/ v8 -## then (for debug) run: scons mode=debug library=shared -## once that is done, run: install_name_tool -id /usr/local/v8/libv8_g.dylib libv8_g.dylib - -BUILD_TARGET = build/core -V8_DIR = /usr/local/v8/libv8_g.dylib -V8_INC = /usr/local/v8/include - -SOURCES = $(SRC_DIR)/main.cpp \ - $(SRC_DIR)/System/system.cpp \ - $(SRC_DIR)/Env/env.cpp \ - $(SRC_DIR)/Directory/directory.cpp \ - $(SRC_DIR)/File/file.cpp \ - $(SRC_DIR)/Http/url.cpp \ - $(SRC_DIR)/Path/path.cpp \ - $(SRC_DIR)/Path/pathHistory.cpp \ - $(SRC_DIR)/Module/module.cpp - -HEADERS = -I/usr/local/include \ - -I$(V8_INC) \ - -I$(SRC_DIR) \ - -I$(SRC_DIR)/Headers \ - -I$(SRC_DIR)/System \ - -I$(SRC_DIR)/Env \ - -I$(SRC_DIR)/Directory \ - -I$(SRC_DIR)/File \ - -I$(SRC_DIR)/Path \ - -I$(SRC_DIR)/Module - -LIBS = $(V8_DIR) - -TARGET = $(BUILD_TARGET) - -OBJS = $(SOURCES:.cpp=.o) -CC=g++ -CXXFLAGS= -arch i386 -Wall -lpthread - -all: $(OBJS) - $(CC) $(CXXFLAGS) $(HEADERS) $(SOURCES) -o $(TARGET) $(LIBS) -clean: - rm -rf build/* diff --git a/SConstruct b/SConstruct index 47e1d3d..a7b275d 100644 --- a/SConstruct +++ b/SConstruct @@ -7,20 +7,23 @@ src_dir = src + "/%s" headers = [ "/usr/local/v8", "/usr/local/v8/include", - "/usr/local/lib" + '/usr/local/Cellar/libevent/2.0.10/include', +# "/usr/local/lib" ] headers.extend(["src/%s/" % name for name in os.listdir(src) if os.path.isdir(os.path.join(src, name))]) lib_sources = ["%s/%s" % (root, name) for root, dir, files in os.walk(src) for name in files if not name.startswith('main') and not name.endswith("os") and not name.endswith(".h")] lib_paths = [ - '/usr/local/lib', + '/usr/local/Cellar/libevent/2.0.10/lib', +# '/usr/local/lib', '/usr/local/v8', '/usr/local/v8/include' ] libs = [ - "libv8", + "libv8_g", "libevent", + "libevent_pthreads" ] flags = [ @@ -34,7 +37,9 @@ env = Environment(ENV=os.environ) env.Append(LIBPATH=lib_paths, LIBS=libs) env.Append(CPPPATH=headers) env.Append(CPPFLAGS=flags) + env.Depends(lib_target, 'libv8') +env.Depends(lib_target, 'libevent') conf = Configure(env) diff --git a/bak_SConstruct b/bak_SConstruct index ce756ae..cababca 100644 --- a/bak_SConstruct +++ b/bak_SConstruct @@ -48,6 +48,7 @@ libs = [ flags = [ "-Wall", "-pthread", + "-fno-common" ] env.Append(CPPPATH=lib_headers) diff --git a/blah1.txt b/blah1.txt deleted file mode 100644 index cc86d22..0000000 --- a/blah1.txt +++ /dev/null @@ -1 +0,0 @@ -some text to put into the file \ No newline at end of file diff --git a/blah2.txt b/blah2.txt deleted file mode 100644 index e69de29..0000000 diff --git a/build.sh b/build.sh deleted file mode 100755 index 416e2bf..0000000 --- a/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env sh -clear && -clear && -clear && -clear && -clear && -make clean && -make \ No newline at end of file diff --git a/embed_testing/SConstruct b/embed_testing/SConstruct new file mode 100644 index 0000000..c0109f0 --- /dev/null +++ b/embed_testing/SConstruct @@ -0,0 +1,42 @@ +import os + +core_src = "/Users/wescope/Desktop/wess/CoreJS/src" + +headers = [ + "/usr/local/v8", + "/usr/local/v8/include", + "/usr/local/lib", + core_src, +] + +headers.extend(["%s/%s/" % (core_src, name) for name in os.listdir(core_src) if os.path.isdir(os.path.join(core_src, name))]) + +lib_sources = ["main.cpp"] + +lib_paths = [ + '/usr/local/lib', + '/usr/local/v8', + '/usr/local/v8/include', + "/Users/wescope/Desktop/wess/CoreJS/build", +] + +libs = [ + "libv8", + "libevent", + "libcore", +] + +flags = [ + "-Wall", + "-pthread", + "-mmacosx-version-min=10.4", + "-pedantic", +] + +env = Environment(ENV=os.environ) +env.Append(LIBPATH=lib_paths, LIBS=libs) +env.Append(CPPPATH=headers) +env.Append(CPPFLAGS=flags) + + +env.Program(target="build/testing", source=lib_sources) \ No newline at end of file diff --git a/embed_testing/build/testing b/embed_testing/build/testing new file mode 100755 index 0000000000000000000000000000000000000000..6e7877aef80a2db7df27901a5f1246f2614dd024 GIT binary patch literal 9396 zcmeHNZ)_aJ6`%E86XP160YfM)$f3Ac4Y8dx6i0#fOuS{SxWU9mxS{Q^KCkVq?w|J0 z)wXo4=_M#9E0tA26{#xXV}w-6AE*^RlpKNZM`}xu5b_743PhDdp%O(1StxM*z1dmc z-ky_usZ^=jr<jG{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eNdsCtH%+60or( z`8L^h$@UJ}{!spY?v?aj+1@YP7bSm7+fio}fhYn|1fmE;5r`rXMIeem6oDuLQ3Rq0 zL=lK0@L!3*O-YWc$oYAW>uNif)zhZ4zzYNH5o>UzD@hkb;)0w{;m#Nr+DldM7@}5F zR>b&FKRWJwFJop$GU|~-6MTFxeW3q@5U`Ro!qLNr#_fH!xoD^bTzgsCW~Vu?W~gV( z>lt?j&794rblccBg3HH)dpw27t=YqpJ=aCkNX_e9$KL}?hb-pN=i~Fh^R8o~--i~? z+HFU-9F}5n&U!PtnPqc_Cx@(AW*OOnY2~u)n8IS2IhZk0u4CX!hHan90B zcv+#-tr%O~f$ER9u~_^p&TU#!Y_Y(89izLx7+az06jjgdgfJ;|;2`B=`Tqqvvm!bs z&qsDkx*+MFOWHp_p}YJJx>}OwH3gy}>)(Su1v=4QKj-plQY(?KKP->8H1mm&HVFoXPlkB)oV zj6D$I)6pP4oBW@IXda?*{KOI{G$T4oq%qWkvHzfN?=Oos z67+y+LgAs&haVgo<$Q#TB;|SWmj-XlLC(z_UDGozau+xCqAhqnH7`s!LjQ~qd5TN^ r=H&Ks-y6(ZBB2#5NwIbb-*VM%#SrVYaixOV;`QULTyM=by@dV)zEK~G literal 0 HcmV?d00001 diff --git a/embed_testing/main.cpp b/embed_testing/main.cpp new file mode 100644 index 0000000..9020f1d --- /dev/null +++ b/embed_testing/main.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main (int argc, char const *argv[]) +{ + printf("\nTesting\n"); + return 0; +} \ No newline at end of file diff --git a/embed_testing/main.o b/embed_testing/main.o new file mode 100644 index 0000000000000000000000000000000000000000..871815b3ba848ed53c2b6c648f770421fb8ea274 GIT binary patch literal 2908 zcmb7GUuauZ7(ZQOTe~cYI$aeDRi+!xYP%KMDg$eG*%|G$HW`GeJ!WazUTBh%dvD1K zk&aGX2*o`p3W5xLDSO(3l)hNQs&j>beKYv1v`|GKqYUfsJNKM6o>f;5Ir*LM-|u|i zx#ymHzW?*rzZw~L@8oE94nKjn( z(|Wd`w_$@F0$#0oUc_+E?Hn)u9OZMr#Cfr>#EaeyUOczJ zONE6EqTpM%dC@BKl6Au$-sbZjdZFx_OAO{Un9IP*Eo;4we`iV4<}qIKD%(Wi#R$AM zc)hh0USvHt!ylEeSnGW2Y=v(@O{SNvHRr|I!aDQ5-8`~O@Y-&{bA<|X8)VcSuxOvl z<#&&V7vEl|`Io5>nUkM{_CXS#m&1$Yrz-E2!yi*R;YFl0_f7oG)fHM6tV#r{Qswg} zw<&fk#ll@I*YCB)C30I`q5thBiHL-JOBOmUM3rOZdT%<-QdP7zHk+gtBjCnAW+{5r zxx(E#ul-V?y0yiacer*=UV4<~l10|)eTroY_?q^aT!7V;<`{M8jk8&qE>&rj%{_Tndmm6nTGNfL^Zy`n53q4@njxG5iB`aLm=4{{7I( zX8J3&=`X7$+aCR&P&|9}fBHWD9A!PmSbIMZ6}27%J`DL;AQq;T);j|En!=>QULfAt zcFG6uY&(EjXc&KZ=i6zkJp$|jV*OjG?t_e-dS;-Y8LuBFlS*E|&Uy$55 z%UYEE63KAtBuBKb(8HL&2@j203%W8%`G_H(FyskCK5xi_hCFY`9~d$|Oy{HSiL{+L zleUHjVj_B+ex!bFAnJ5E_Dsr})}o!a(sCSid+e+uE+m{(7hO5}JEfBtb+Te2kr|y# z!A&Id36a1(3|A83GlNdapmf5{Ffrx14uy>8^I|HMbF!Jlr0rf5(;XDLONK9`CYYdD zIS{7@Uw^f4P>3^9=f@0ob_+3`%GqNV#dt33P2r#$8c3#xQ5bo2bqe9gTa&!l*_d$# zcc^Sepn~o1H_08gttfkhu(Naxge=_TnCM`G{T +#include + +using namespace std; +using namespace v8; +using namespace Core; + + +static int SetNonBlocking(int fd) { + int flags = fcntl(fd, F_GETFL, 0); + if (flags == -1) + flags = 0; + return fcntl(fd, F_SETFL, flags | O_NONBLOCK); +} + + +ThreadPool *myThreadPool = ThreadPool::instance(); +BaseEvent *myEvents = BaseEvent::instance(); + + +char *MainReadFile(const char *name) +{ + FILE *readFile = fopen(name, "rb"); + if(readFile == NULL) + return NULL; + + fseek(readFile, 0, SEEK_END); + int size = ftell(readFile); + rewind(readFile); + + char *chars = new char[size + 1]; + chars[size] = '\0'; + + for(int i = 0; i < size;) + { + int read = fread(&chars[i], 1, size - i, readFile); + i += read; + } + + fclose(readFile); + + return chars; +} + +void AtExit() +{ + fflush(stdout); + fflush(stderr); +} + + +int RunCore (int argc, char const *argv[]) +{ + + string filename; + filename = (argc > 1)? string(argv[1]) : "main.js"; + + char currentPath[FILENAME_MAX]; + getcwd(currentPath, sizeof(currentPath)); + + char fullpath[100]; + + strcpy(fullpath, currentPath); + strcat(fullpath, "/"); + + const char *Cfilename = filename.c_str(); + strcat(fullpath, Cfilename); + + struct stat fileStat; + int statRes; + + statRes = stat(fullpath, &fileStat); + if(statRes == -1) + { + printf("\nCould not find file: %s\n", fullpath); + return 0; + } + + char pathBuffer[PATH_MAX + 1]; + + string mainpath = string(realpath(__FILE__, pathBuffer)); + mainpath = mainpath.substr(0, mainpath.rfind('/')); + + + + V8::Initialize(); + HandleScope scope; + + Handle global = ObjectTemplate::New(); + global->Set(String::New("JS_SYS_PATH"), String::New(mainpath.c_str())); + + Core::System::Init(global); + Core::Env::Init(global); + Core::Directory::Init(global); + Core::File::Init(global); + Core::Module::Init(global); + Core::Http::Init(global); + Core::Socket::Init(global); + + PersistentbaseContext_ = Context::New(NULL, global); + Context::Scope contextScope(baseContext_); + + Core::System::ExecuteString (String::New(MainReadFile(fullpath)), String::New(filename.c_str()), true, true); + + pthread_mutex_lock(&myThreadPool->threadLock); + if(myThreadPool->eventCnt>0){ + + int fds[2]; + if (pipe(fds)) { + cerr << "pipe() failed, errno: " << errno; + return false; + } + + if (SetNonBlocking(fds[0])) { + cerr << "SetNonBlocking for pipe fd[0] failed, errno: " << errno; + return false; + } + + myThreadPool->wakeup_pipe_out = fds[0]; + myThreadPool->wakeup_pipe_in = fds[1]; + + myThreadPool->wakeup_event = event_new(myEvents->base, myThreadPool->wakeup_pipe_out, EV_READ|EV_PERSIST, ThreadPool::onNotify, (void *)""); + event_add(myThreadPool->wakeup_event, NULL); + + } + pthread_mutex_unlock(&myThreadPool->threadLock); + + evthread_use_pthreads(); + + event_base_dispatch(myEvents->base); + + + baseContext_.Dispose(); + V8::Dispose(); + + close(myThreadPool->wakeup_pipe_in); + close(myThreadPool->wakeup_pipe_out); + delete myThreadPool; + free(myEvents); + atexit(AtExit); + + return 0; +} \ No newline at end of file diff --git a/src/core.h b/src/core.h index e9a465b..543f5a7 100755 --- a/src/core.h +++ b/src/core.h @@ -14,4 +14,7 @@ #include "threadPool.h" #include "Socket.h" + +int RunMain (int argc, char const *argv[]); + #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ca45a30..ff08b17 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -144,7 +144,9 @@ int RunMain (int argc, char const *argv[]) return 0; } +/* int main (int argc, char const *argv[]) { return RunMain(argc, argv); -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/test/testmodule/Makefile b/test/testmodule/Makefile deleted file mode 100644 index 20cebe7..0000000 --- a/test/testmodule/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -V8_DIR = /usr/local/v8/libv8_g.dylib -V8_INC = /usr/local/v8/include - -SOURCES = testmod.cpp - - -HEADERS = -I$(V8_INC) \ - -I. \ - -LIBS = $(V8_DIR) - -TARGET = testmod.fm - -OBJS = $(SOURCES:.cpp=.o) -CC=g++ -CXXFLAGS= -arch i386 -Wall -lpthread -shared -rdynamic - -all: $(OBSJ) - $(CC) $(CXXFLAGS) $(HEADERS) $(SOURCES) -o $(TARGET) $(LIBS) - -clean: - rm -rf testmod.fm