Explorar o código

Change CSWorker to be a module.

Bentley James Oakes %!s(int64=7) %!d(string=hai) anos
pai
achega
bc721fbdc8
Modificáronse 3 ficheiros con 45 adicións e 26 borrados
  1. 11 10
      __worker.js
  2. 1 0
      asworker.js
  3. 33 16
      csworker.js

+ 11 - 10
__worker.js

@@ -106,15 +106,14 @@
 
 /**************************** LIBRARIES and GLOBALS ****************************/
 var  _util 	= require('util'),
-	 _path 	= require('path'),
+	 //_path 	= require('path'),
 	 _http 	= require('http'),
 	 _do  	= require('./___do'),
 	 _fs 	 	= _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']),
-	 _fspp	= _do.convert(require('./___fs++'), ['mkdirs']),	 
-	 _siocl	= require('socket.io-client'),
+	//_fspp	= _do.convert(require('./___fs++'), ['mkdirs']),
 	 _utils	= require('./utils'),
-	 _styleinfo = require('./styleinfo'),
-	 _svg		= require('./libsvg').SVG,
+	 //_styleinfo = require('./styleinfo'),
+	 //_svg		= require('./libsvg').SVG,
 	 _wlib,
 	 _mmmk,
 	 _mt,
@@ -498,11 +497,13 @@ process.on('message',
 			__wtype = msg['workerType'];
 			__wid   = msg['workerId'];
 
-			if (__wtype == "/asworker"){
-				_wlib = require("./asworker");
-			}else {
-                _wlib = eval('(' + _fs.readFileSync('.' + __wtype + '.js', 'utf8') + ')');
-			}
+            if (__wtype == "/asworker") {
+                _wlib = require("./asworker");
+            } else if (__wtype == "/csworker") {
+                _wlib = require("./csworker");
+            } else {
+                throw "Error! Unknown worker type: " + __wtype;
+            }
 			_mmmk   = require('./mmmk');
 
             _mt  	  = require('./libmt');

+ 1 - 0
asworker.js

@@ -5,6 +5,7 @@
 const {
     __errorContinuable,
     __httpReq,
+	__wHttpReq,
     __postInternalErrorMsg, __postMessage,
     __sequenceNumber,
     __successContinuable,

+ 33 - 16
csworker.js

@@ -177,7 +177,24 @@
 			SYSOUT message announcing the launching of the rule... a sensible and 
 		  	nice solution would be not to remember such changelogs in
 			__handledSeqNums */
-{
+const {
+    __errorContinuable,
+    __httpReq,
+	__wHttpReq,
+    __postInternalErrorMsg, __postMessage,
+    __sequenceNumber,
+    __successContinuable,
+	__uri_to_id
+} = require("./__worker");
+
+const _do = require("./___do");
+const _utils = require('./utils');
+const _mmmk = require("./mmmk");
+const _fs = _do.convert(require('fs'), ['readFile', 'writeFile', 'readdir']);
+
+const _siocl = require('socket.io-client');
+
+module.exports = {
 	'__REGEN_ICON_RETRY_DELAY_MS':200,
 	'__asmm2csmm':{},
 	'__asid2csid':{},
@@ -212,8 +229,8 @@
 	'__applyASWChanges' :
 		function(changelog,aswSequenceNumber,hitchhiker)
 		{
-			console.error('w#'+__wid+' ++ ('+aswSequenceNumber+') '+
-							_utils.jsons(changelog));
+			//console.error('w#'+__wid+' ++ ('+aswSequenceNumber+') '+
+			//				_utils.jsons(changelog));
 
 
 			if( _utils.sn2int(aswSequenceNumber) > 
@@ -538,8 +555,8 @@
 				{
 					var cschangelog = _utils.flatten(cschangelogs);
 
-					console.error('w#'+__wid+' -- ('+aswSequenceNumber+') '+
-						_utils.jsons(cschangelog));
+					//console.error('w#'+__wid+' -- ('+aswSequenceNumber+') '+
+					//	_utils.jsons(cschangelog));
 
 					__postMessage(
 							{'statusCode':200,
@@ -647,7 +664,7 @@
 												{
 													return self.__sn2int(pc['sequence#']) > 
 																self.__sn2int(
-																	self.__nextASWSequenceNumber)
+																	self.__nextASWSequenceNumber);
 												});
 										callback();
 										self.__applyPendingASWChanges();
@@ -713,7 +730,7 @@
 					 pp  		= _svg.fns.getPointOnPathAtRatio(path,ldi.xratio);
                      
                 if (pp == undefined)
-                    continue
+                    continue;
                 
 				var yoffset	= new _svg.types.Point(0,ldi.yoffset).rotate(pp.O),
 					endAt	= (ldi.xratio >= 1 ? 
@@ -876,12 +893,12 @@
 			//			new_node['$linktype'] = this.metamodels[metamodel]['connectorTypes'][type];	
 
 			return [];
-			return [{'op':'SYSOUT',
-			  		  'text':'WARNING :: '+
-						  		'a proper layout constraint solver has yet to be '+
-						  		'implemented... inter-VisualObject relationships are '+
-								'ignored and containers do not resize to fit their '+
-								'contents'}];
+			// return [{'op':'SYSOUT',
+			//   		  'text':'WARNING :: '+
+			// 			  		'a proper layout constraint solver has yet to be '+
+			// 			  		'implemented... inter-VisualObject relationships are '+
+			// 					'ignored and containers do not resize to fit their '+
+			// 					'contents'}];
 		},
 
 
@@ -1834,8 +1851,8 @@
                             function(result) {
                                 return __wHttpReq('PUT',
                                            uri+'?wid='+aswid,
-                                           ({'csm':_mmmk.read(), 'asmm': asmm}))
-                            }]
+                                           ({'csm':_mmmk.read(), 'asmm': asmm}));
+                            }];
                  } else {
                      actions = [__wHttpReq('PUT',
                                            uri+'?wid='+aswid,
@@ -2247,4 +2264,4 @@
 		{
 			return parseInt(sn.match(/.*#(\d*)/)[1]);
 		}
-}
+};