Commit e8fec70b authored by Vivek's avatar Vivek

wip

parent 96288880
......@@ -288,7 +288,7 @@
</tuple>
<state>
<tuple>
<float>1436446773.66</float>
<float>1436545182.61</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -119,7 +119,6 @@
<script src="renderjs.js" type="text/javascript"></script>\n
<script src="handlebars.js" type="text/javascript"></script>\n
<script src="jquery.js" type="text/javascript"></script>\n
<script src="gadget_interfaces.js" type="text/javascript"></script>\n
\n
<!-- custom script -->\n
<script src="gadget_interfacedemo.js" type="text/javascript"></script>\n
......@@ -288,7 +287,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>944.17439.65022.59426</string> </value>
<value> <string>944.18548.40475.62395</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -306,7 +305,7 @@
</tuple>
<state>
<tuple>
<float>1436452642.01</float>
<float>1436518406.8</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -104,6 +104,9 @@
(function (window, rJS, Handlebars, $, jQuery, RSVP) {\n
"use strict";\n
\n
var INTERFACE_GADGET_URL = "./gadget_interfaces.html",\n
INTERFACE_GADGET_SCOPE = "interface";\n
\n
rJS(window)\n
.ready(function (g) {\n
g.props = {};\n
......@@ -123,20 +126,38 @@
})\n
\n
.declareMethod("method1", function (param1, param2) {\n
console.log("RJS IDemo JS: declareMethod: method1");\n
return;\n
})\n
.declareMethod("method2", function (param1) {\n
console.log("RJS IDemo JS: declareMethod: method2");\n
return;\n
})\n
.declareMethod("method3", function () {\n
return;\n
})\n
\n
.declareMethod("interfaceGadgetTest", function (gadget, interface_gadget, interface_list) {\n
var interface_name = interface_list[0];\n
return new RSVP.Queue()\n
.push(function () {\n
return interface_gadget.getInterfaceData(interface_name);\n
})\n
.push(function (interface_data) {\n
console.log("interface_data", interface_data);\n
return interface_gadget.verifyInterfaceImplementation(gadget, interface_name);\n
})\n
.push(function (verification_status) {\n
console.log("Verification:", verification_status);\n
});\n
})\n
\n
.declareMethod("render", function () {\n
var gadget = this;\n
return new RSVP.Queue()\n
.push(function () {\n
return gadget.declareGadget(INTERFACE_GADGET_URL, {\n
scope: INTERFACE_GADGET_SCOPE,\n
element: gadget.__element\n
});\n
})\n
.push(function () {\n
return gadget.getInterfaceList();\n
})\n
......@@ -154,15 +175,15 @@
gadget.props.content_element.innerHTML =\n
gadget.props.interface_list_template(parameter);\n
$(gadget.props.element).trigger("create");\n
return parameter.interface_item;\n
})\n
.push(function (interface_items) {\n
// testing getInterfaceData.\n
return gadget.getInterfaceData(interface_items[0].interface_name);\n
return RSVP.all([\n
gadget.getDeclaredGadget(INTERFACE_GADGET_SCOPE),\n
interface_list\n
]);\n
})\n
.push(function (interface_data) {\n
console.log("interface_data", interface_data);\n
console.log("getPath", gadget.getPath());\n
.push(function (interface_gadget_list) {\n
var interface_gadget = interface_gadget_list[0],\n
interface_list = interface_gadget_list[1];\n
return gadget.interfaceGadgetTest(gadget, interface_gadget, interface_list);\n
});\n
});\n
\n
......@@ -301,7 +322,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>944.17453.1344.10683</string> </value>
<value> <string>944.18996.27011.18756</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -319,7 +340,7 @@
</tuple>
<state>
<tuple>
<float>1436453615.05</float>
<float>1436545240.66</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -151,25 +151,89 @@
(function (window, rJS, Handlebars, $, RSVP, loopEventListener, DOMParser) {\n
"use strict";\n
\n
function verifyInterfaceDeclaration (gadget) {\n
return;\n
function verifyInterfaceDefinitiion (interface_name) {\n
//to verify if interface definition follows the correct template.\n
}\n
\n
function verifyAllMethodsDeclared (interface_methods, gadget_methods) {\n
return;\n
function verifyInterfaceDeclaration (interface_name, declared_interfaces) {\n
//to verify if gadget declares the interface.\n
return declared_interfaces.indexOf(interface_name) > -1;\n
}\n
\n
function verifyAllMethodsDeclared (interface_methods, gadget_methods) {\n
//to verify if all the interface methods are declared by the gadget.\n
var gadget_methods_names = [],\n
interface_methods_names = [];\n
for (var i=0; i<gadget_methods.length; i+=1) {\n
gadget_methods_names.push(gadget_methods[i].name);\n
}\n
for (var j=0; j<interface_methods.length; j+=1) {\n
interface_methods_names.push(interface_methods[j].name);\n
}\n
for (var k=0; k<interface_methods_names.length; k+=1) {\n
if(gadget_methods_names.indexOf(interface_methods_names[k]) < 0) {\n
return false;\n
}\n
}\n
return true;\n
}\n
\n
function verifyAllMethodsSignature (interface_methods, gadget_methods) {\n
//to verify if all the declared methods match the signature of the interface methods.\n
var interface_methods_dict = {},\n
gadget_methods_dict = {};\n
for(var i=0; i<interface_methods.length; i+=1) {\n
interface_methods_dict[interface_methods[i].name] = interface_methods[i];\n
}\n
for(var j=0; j<gadget_methods.length; j+=1) {\n
gadget_methods_dict[gadget_methods[j].name] = gadget_methods[j];\n
}\n
for(var item in interface_methods_dict) {\n
if(!verifyMethodSignature(interface_methods_dict[item], gadget_methods_dict[item])) {\n
return false;\n
}\n
}\n
return true;\n
}\n
\n
function verifyMethodSignature (interface_method, gadget_method) {\n
return;\n
//to verify if two methods have the same signature\n
var max_arg_len = interface_method.argument_list.length,\n
min_arg_len = 0;\n
if (max_arg_len) {\n
var argument_list = interface_method.argument_list;\n
for (var i=0; i<argument_list.length; i+=1) {\n
if (argument_list[i].required) {\n
min_arg_len += 1;\n
}\n
}\n
}\n
return (gadget_method.arg_len >= min_arg_len && gadget_method.arg_len <= max_arg_len);\n
}\n
\n
rJS(window)\n
.ready(function (g) {\n
g.props = {};\n
})\n
\n
.declareMethod("getDeclaredGadgetInterfaces", function (gadget) {\n
return RSVP.Queue()\n
.push(function() {\n
return gadget.getInterfaceList();\n
})\n
.push(function (declared_interfaces) {\n
return declared_interfaces;\n
});\n
})\n
\n
.declareMethod("getDeclaredGadgetMethods", function (gadget) {\n
return;\n
return RSVP.Queue()\n
.push(function() {\n
return gadget.getDeclaredMethodList();\n
})\n
.push(function (declared_methods) {\n
return declared_methods;\n
});\n
})\n
\n
.declareMethod("getInterfaceData", function (interface_name) {\n
......@@ -192,31 +256,22 @@
dl_count = 1;\n
interface_data.name = doc.getElementsByTagName(\'h1\')[0].innerText;\n
interface_data.description = doc.getElementsByTagName(\'h3\')[0].innerText;\n
\n
for (var i=0; i<method_len; i+=1) {\n
var method = {\n
name: "",\n
description: "",\n
name: dt_list[dt_count].innerText,\n
description: dd_list[dt_count].innerText,\n
argument_list: []\n
};\n
method.name = dt_list[dt_count].innerText;\n
method.description = dd_list[dt_count].innerText;\n
var argument_len = dl_list[dl_count].getElementsByTagName(\'dt\').length;\n
},\n
argument_len = dl_list[dl_count].getElementsByTagName(\'dt\').length;\n
dt_count += 1;\n
dl_count += 1;\n
for (var j=0; j<argument_len; j+=1) {\n
var argument_item = {\n
name: "",\n
description: "",\n
required: true,\n
type: ""\n
name: dt_list[dt_count].innerText,\n
description: dd_list[dt_count].innerText,\n
required: dt_list[dt_count].getAttribute("class") === "optional" ? false:true,\n
type: dt_list[dt_count].getAttribute("type")\n
};\n
if(dt_list[dt_count].getAttribute("class") == "optional") {\n
argument_item.required = false;\n
}\n
argument_item.type = dt_list[dt_count].getAttribute("type");\n
argument_item.name = dt_list[dt_count].innerText;\n
argument_item.description = dd_list[dt_count].innerText;\n
dt_count += 1;\n
method.argument_list.push(argument_item);\n
}\n
......@@ -224,7 +279,6 @@
}\n
return interface_data;\n
});\n
\n
})\n
\n
.declareMethod("getDefinedInterfaceMethods", function (interface_name) {\n
......@@ -233,9 +287,53 @@
return interface_data.methods;\n
});\n
})\n
\n
\n
.declareMethod("verifyInterfaceImplementation", function (gadget, interface_name) {\n
return;\n
var interface_gadget = this;\n
return RSVP.Queue()\n
.push(function () {\n
return interface_gadget.getDeclaredGadgetInterfaces(gadget);\n
})\n
.push(function (declared_interfaces) {\n
return verifyInterfaceDeclaration(interface_name, declared_interfaces);\n
})\n
.push(function (verified) {\n
if (!verified) {\n
throw new Error("Interface not declared.");\n
}\n
return RSVP.all([\n
interface_gadget.getDefinedInterfaceMethods(interface_name),\n
interface_gadget.getDeclaredGadgetMethods(gadget)\n
]);\n
})\n
.push(function(methods_list) {\n
return verifyAllMethodsDeclared(methods_list[0], methods_list[1]);\n
})\n
.push(function (verified) {\n
if (!verified) {\n
throw new Error("All methods are not declared.");\n
}\n
return RSVP.all([\n
interface_gadget.getDefinedInterfaceMethods(interface_name),\n
interface_gadget.getDeclaredGadgetMethods(gadget)\n
]);\n
})\n
.push(function(methods_list) {\n
return verifyAllMethodsSignature(methods_list[0], methods_list[1]);\n
})\n
.push(function (verified) {\n
if (!verified) {\n
throw new Error("All methods signature do not match.");\n
}\n
})\n
.push (function() {\n
console.log("Verified : Success");\n
return true;\n
}, function(error_message) {\n
console.log("Verified : Failure", error_message);\n
return false;\n
});\n
\n
});\n
\n
}(window, rJS, Handlebars, jQuery, RSVP, loopEventListener, DOMParser));
......@@ -375,7 +473,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>944.17466.54680.49015</string> </value>
<value> <string>944.18970.20251.32904</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -393,7 +491,7 @@
</tuple>
<state>
<tuple>
<float>1436453641.0</float>
<float>1436544696.2</float>
<string>GMT</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment