Navigation Menu

Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Commit

Permalink
Added and started develing embedding test project, working on correct…
Browse files Browse the repository at this point in the history
… linking
  • Loading branch information
wess committed Apr 30, 2011
1 parent 5c2ddbd commit dfda992
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 135 deletions.
56 changes: 0 additions & 56 deletions Makefile

This file was deleted.

44 changes: 0 additions & 44 deletions Makefile_run

This file was deleted.

11 changes: 8 additions & 3 deletions SConstruct
Expand Up @@ -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 = [
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions bak_SConstruct
Expand Up @@ -48,6 +48,7 @@ libs = [
flags = [
"-Wall",
"-pthread",
"-fno-common"
]

env.Append(CPPPATH=lib_headers)
Expand Down
1 change: 0 additions & 1 deletion blah1.txt

This file was deleted.

Empty file removed blah2.txt
Empty file.
8 changes: 0 additions & 8 deletions build.sh

This file was deleted.

42 changes: 42 additions & 0 deletions 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)
Binary file added embed_testing/build/testing
Binary file not shown.
8 changes: 8 additions & 0 deletions embed_testing/main.cpp
@@ -0,0 +1,8 @@
#include <stdio.h>
#include <core.h>

int main (int argc, char const *argv[])
{
printf("\nTesting\n");
return 0;
}
Binary file added embed_testing/main.o
Binary file not shown.
145 changes: 145 additions & 0 deletions src/core.cpp
@@ -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;
}
3 changes: 3 additions & 0 deletions src/core.h
Expand Up @@ -14,4 +14,7 @@
#include "threadPool.h"
#include "Socket.h"


int RunMain (int argc, char const *argv[]);

#endif
4 changes: 3 additions & 1 deletion src/main.cpp
Expand Up @@ -144,7 +144,9 @@ int RunMain (int argc, char const *argv[])
return 0;
}

/*
int main (int argc, char const *argv[])
{
return RunMain(argc, argv);
}
}
*/

0 comments on commit dfda992

Please sign in to comment.