Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julian Frosch
BezLinApp
Commits
621e27f2
Commit
621e27f2
authored
Jan 24, 2016
by
Julian Frosch
Browse files
Added some stuff for multi-threading
parent
835bab94
Changes
5
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
621e27f2
# THIS BRANCH IS ONLY FOR TESTING AND DEMONSTRATION OF MULTICORE-USE!
# BezLinApp for node.js and electron
# BezLinApp for node.js and electron
This is an application written with node.js and electron that tries to do a piecewise linear approximation on Bezier curves in a given SVG-file.
This is an application written with node.js and electron that tries to do a piecewise linear approximation on Bezier curves in a given SVG-file.
## How to start
## How to start
Before starting, npm is required.
Before starting, npm is required.
In order to test the program, clone the repo, cd into it's directory and run
In order to test the program, clone the repo, cd into it's directory and run
```
```
npm install
npm install
```
```
...
...
index.html
View file @
621e27f2
...
@@ -6,9 +6,6 @@
...
@@ -6,9 +6,6 @@
</head>
</head>
<body>
<body>
<h1>
Hello World!
</h1>
<h1>
Hello World!
</h1>
We are using node
<script>
document
.
write
(
process
.
versions
.
node
)
</script>
,
Chrome
<script>
document
.
write
(
process
.
versions
.
chrome
)
</script>
,
and Electron
<script>
document
.
write
(
process
.
versions
.
electron
)
</script>
.
<div
id=
"svgHolder"
class=
"holder"
>
<div
id=
"svgHolder"
class=
"holder"
>
Drag your svg-file here!
Drag your svg-file here!
...
...
js/script.js
View file @
621e27f2
...
@@ -7,12 +7,35 @@ $(function(){
...
@@ -7,12 +7,35 @@ $(function(){
svgHolder
.
ondragleave
=
svgHolder
.
ondragend
=
function
()
{
svgHolder
.
ondragleave
=
svgHolder
.
ondragend
=
function
()
{
return
false
;
return
false
;
};
};
/*
Here, we try some things with multiple processes:
*/
var
fork
=
require
(
'
child_process
'
).
fork
;
// get this machine's number of CPUs
var
numCPUs
=
require
(
"
os
"
).
cpus
().
length
;
console
.
log
(
"
Number of cores:
"
+
numCPUs
);
// create one child for every core
var
children
=
[];
for
(
var
i
=
0
;
i
<
numCPUs
;
i
++
)
{
// fork-command takes the foreign script, arguments and further options as params
children
[
i
]
=
fork
(
'
./js/thread_test/thread.js
'
,
[
i
]);
// listen on messages from the children, print info and kill it
children
[
i
].
on
(
'
message
'
,
function
(
m
)
{
var
child_id
=
m
.
c_id
;
console
.
log
(
"
Got message from child
"
+
child_id
);
children
[
child_id
].
kill
();
});
}
// When the user drops the file
// When the user drops the file
svgHolder
.
ondrop
=
function
(
e
)
{
svgHolder
.
ondrop
=
function
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
var
file
=
e
.
dataTransfer
.
files
[
0
];
var
file
=
e
.
dataTransfer
.
files
[
0
];
// TODO: check for filetype (maybe via regex)
// TODO: check for filetype (maybe via regex)
// TODO: remove
// TODO: remove
console
.
log
(
'
File you dragged here is
'
,
file
.
path
);
console
.
log
(
'
File you dragged here is
'
,
file
.
path
);
...
@@ -29,5 +52,13 @@ $(function(){
...
@@ -29,5 +52,13 @@ $(function(){
}
}
});
});
/*
More cool multi-core-stuff!
Send a message to every child. Each child will send something back, which
results in the parent killing it.
*/
children
.
forEach
(
function
(
child
)
{
child
.
send
({
content
:
"
do something!
"
});
});
};
};
});
});
js/thread_test/thread.js
0 → 100644
View file @
621e27f2
var
id
=
process
.
argv
[
2
];
console
.
log
(
"
Child
"
+
id
+
"
started!
"
);
process
.
on
(
'
message
'
,
function
(
m
)
{
// child got message
console
.
log
(
"
Child
"
+
id
+
"
got message:
"
+
m
.
content
);
process
.
send
({
c_id
:
id
,
content
:
"
success
"
});
})
main.js
View file @
621e27f2
...
@@ -3,7 +3,7 @@ const app = electron.app; // Module to control application life.
...
@@ -3,7 +3,7 @@ const app = electron.app; // Module to control application life.
const
BrowserWindow
=
electron
.
BrowserWindow
;
// Module to create native browser window.
const
BrowserWindow
=
electron
.
BrowserWindow
;
// Module to create native browser window.
// Report crashes to our server.
// Report crashes to our server.
electron
.
crashReporter
.
start
();
//
electron.crashReporter.start();
// Keep a global reference of the window object, if you don't, the window will
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
// be closed automatically when the JavaScript object is garbage collected.
...
@@ -30,6 +30,9 @@ app.on('ready', function() {
...
@@ -30,6 +30,9 @@ app.on('ready', function() {
// Open the DevTools.
// Open the DevTools.
mainWindow
.
webContents
.
openDevTools
();
mainWindow
.
webContents
.
openDevTools
();
// example: Access arguments
console
.
dir
(
process
.
argv
);
// Emitted when the window is closed.
// Emitted when the window is closed.
mainWindow
.
on
(
'
closed
'
,
function
()
{
mainWindow
.
on
(
'
closed
'
,
function
()
{
// Dereference the window object, usually you would store windows
// Dereference the window object, usually you would store windows
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment