This repository has been archived by the owner on Jun 26, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added and started develing embedding test project, working on correct…
… linking
- Loading branch information
Showing
15 changed files
with
210 additions
and
135 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ libs = [ | |
flags = [ | ||
"-Wall", | ||
"-pthread", | ||
"-fno-common" | ||
] | ||
|
||
env.Append(CPPPATH=lib_headers) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <stdio.h> | ||
#include <core.h> | ||
|
||
int main (int argc, char const *argv[]) | ||
{ | ||
printf("\nTesting\n"); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#include "core.h" | ||
#include "BaseEvent.h" | ||
#include <vector> | ||
#include <algorithm> | ||
|
||
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<ObjectTemplate> 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); | ||
|
||
Persistent<Context>baseContext_ = 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,7 @@ | |
#include "threadPool.h" | ||
#include "Socket.h" | ||
|
||
|
||
int RunMain (int argc, char const *argv[]); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.