update to afb-daemon evolutions
[src/app-framework-demo.git] / afm-client / app / Backend / RestApis / AfmMainMockApi.js
1 /* 
2  * Copyright (C) 2015 "IoT.bzh"
3  * Author "Fulup Ar Foll"
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /* ----------------------------------------------------------------------
20  *   This module simulate Application Framework Binder
21  *   
22  *   /api/afm-main/runnables  // no params
23  *   /api/afm-main/details    &id="xxxx"
24  *   /api/afm-main/start      &id="xxxx"
25  *   /api/afm-main/terminate  &runid="xxxx"
26  *   /api/afm-main/stop       &runid="xxxx"
27  *   /api/afm-main/continue   &runid="xxxx"
28  *   /api/afm-main/runners    // no params
29  *   /api/afm-main/state      &runid="xxxx"
30  * ----------------------------------------------------------------------*/
31
32  
33 function NewApi(handle, prefix) {
34     var scope=this; // I hate JavaScript
35     scope.connected=false;
36     
37     // Simulate Client Context Session Creation
38     handle.app.get (prefix +'/runnables', function (req, res) {
39         var Response= { jtype: "afb-reply",
40                         request: { "prefix": "afm-main", "api": "runnables", "uuid": "e4ef5e66-xxxx", "token": "123456789-xxxxx", "status": "processed" },
41                         response: {runnables: [ 
42                             {id: "webapps-rabbit@0.0", version: "0.0.8", name: "Rabbit", description: "Fun grid game where the rabbit finds and eats the carrots dodging the foxes.", shortname: "", author: "Todd Brandt <todd.e.brandt@intel.com>" },
43                             {id: "webapps-annex@0.0", version: "0.0.10", name: "Annex", description: "Reversi/Othello", shortname: "", author: "Todd Brandt <todd.e.brandt@intel.com>" },
44                             {id: "webapps-memory-match@1.1", version: "1.1.7", name: "MemoryMatch", description: "Memory match", shortname: "", author: "Todd Brandt <todd.e.brandt@intel.com>"  }
45                        ]}};
46                    
47                    /* "jtype":"afb-reply","request":{"prefix":"afm-main","api":"runnables","status":"processed"},"response":{"runnables":[{"id":"webapps-annex@0.0","version":"0.0.10","width":0,"height":0,"name":"Annex","description":"Reversi/Othello","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"},{"id":"webapps-rabbit@0.0","version":"0.0.8","width":0,"height":0,"name":"Rabbit","description":"Fun grid game where the rabbit finds and eats the carrots dodging the foxes.","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"}]}}*/
48                     
49         res.send(Response);
50     });
51     
52     handle.app.get (prefix +'/detail', function (req, res) {
53         var apps = { 
54                     "webapps-rabbit@0.0": {id: "webapps-rabbit@0.0", version: "0.0.8", name: "Rabbit", description: "Fun grid game where the rabbit finds and eats the carrots dodging the foxes.", shortname: "", author: "Todd Brandt <todd.e.brandt@intel.com>" },
55                     "webapps-annex@0.0": {id: "webapps-annex@0.0", version: "0.0.10", name: "Annex", description: "Reversi/Othello", shortname: "", author: "Todd Brandt <todd.e.brandt@intel.com>" },
56                     "webapps-memory-match@1.1": {id: "webapps-memory-match@1.1", version: "1.1.7", name: "MemoryMatch", description: "Memory match", shortname: "", author: "Todd Brandt <todd.e.brandt@intel.com>"  }
57                     };
58                     
59         var Response= { jtype: "afb-reply",
60                         request: { "prefix": "afm-main", "api": "detail", "uuid": "e4ef5e66-xxxx", "token": "123456789-xxxxx", "status": "processed" },
61                         response: apps[req.query.id]
62                        };
63                    
64                    /* "jtype":"afb-reply","request":{"prefix":"afm-main","api":"runnables","status":"processed"},"response":{"runnables":[{"id":"webapps-annex@0.0","version":"0.0.10","width":0,"height":0,"name":"Annex","description":"Reversi/Othello","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"},{"id":"webapps-rabbit@0.0","version":"0.0.8","width":0,"height":0,"name":"Rabbit","description":"Fun grid game where the rabbit finds and eats the carrots dodging the foxes.","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"}]}}*/
65                     
66         res.send(Response);
67     });
68     
69     handle.app.get (prefix +'/start', function (req, res) {
70         var apps = { "runid": 2, "uri": "/opa/images/avatars/tux-bzh.png"}; 
71                     
72         var Response= { jtype: "afb-reply",
73                         request: { "prefix": "afm-main", "api": "start", "uuid": "e4ef5e66-xxxx", "token": "123456789-xxxxx", "status": "processed" },
74                         response: apps
75                        };
76                    
77                    /* "jtype":"afb-reply","request":{"prefix":"afm-main","api":"runnables","status":"processed"},"response":{"runnables":[{"id":"webapps-annex@0.0","version":"0.0.10","width":0,"height":0,"name":"Annex","description":"Reversi/Othello","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"},{"id":"webapps-rabbit@0.0","version":"0.0.8","width":0,"height":0,"name":"Rabbit","description":"Fun grid game where the rabbit finds and eats the carrots dodging the foxes.","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"}]}}*/
78                     
79         res.send(Response);
80     });
81     
82     handle.app.get (prefix +'/terminate', function (req, res) {
83         var apps = {}; 
84                     
85         var Response= { jtype: "afb-reply",
86                         request: { "prefix": "afm-main", "api": "terminate", "uuid": "e4ef5e66-xxxx", "token": "123456789-xxxxx", "status": "processed" },
87                         response: apps
88                        };
89                    
90                    /* "jtype":"afb-reply","request":{"prefix":"afm-main","api":"runnables","status":"processed"},"response":{"runnables":[{"id":"webapps-annex@0.0","version":"0.0.10","width":0,"height":0,"name":"Annex","description":"Reversi/Othello","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"},{"id":"webapps-rabbit@0.0","version":"0.0.8","width":0,"height":0,"name":"Rabbit","description":"Fun grid game where the rabbit finds and eats the carrots dodging the foxes.","shortname":"","author":"Todd Brandt <todd.e.brandt@intel.com>"}]}}*/
91                     
92         res.send(Response);
93     });
94 }
95
96 // Export Class
97 module.exports = NewApi;