Covalent Bond  0.0.1-alpha
'covalent bond' is a data middle office. As a 2022-2023 Fall SWE final project.
api.cpp
Go to the documentation of this file.
1 #include "api.hpp"
3 using namespace wfrest;
4 namespace cb {
5 namespace apiCPP {
6 
7 cb::graph::cbComputeGraph* addGraph(int32_t idx, const std::string& cmd,
10  cbg->setVirtualDeviceManager(vdm);
11  cbg->execScript(cmd);
12  return cbg;
13 }
14 
15 } // namespace apiCPP
16 } // namespace cb
17 
18 namespace cb {
19 namespace trans {
20 void outbase(HttpResp* resp) {
21  resp->String("<html>\n");
22  resp->String("<head>\n");
23  resp->String(" <link "
24  "type=\"text/css\"rel=\"stylesheet\"href=\"https://cdn.jsdelivr.net/npm/"
25  "litegraph.js@0.7.10/css/litegraph.css\">\n");
26  resp->String(" <script "
27  "type=\"text/javascript\"src=\"https://cdn.jsdelivr.net/npm/litegraph.js@0.7.10/"
28  "build/litegraph.min.js\"></script>\n");
29  resp->String("</head>");
30  resp->String("<body style='width:100%; height:100%'>\n");
31  resp->String(
32  " <canvas id='mycanvas' width='1024' height='720' style='border: 1px solid'></canvas>\n");
33  resp->String(" <script>\n");
34  resp->String(" var graph = new LGraph();\n");
35  resp->String(" var canvas = new LGraphCanvas(\"#mycanvas\", graph);\n");
36 }
37 
39  trivial::cbMySqlDevice* leafNode) {
40  int posx = 100;
41  int posy = leafMapStruct.posy;
42  int nodeCode = leafMapStruct.nodeCode;
43  std::string outtext, outtext2;
44  outtext = " function leafNode" + std::to_string(nodeCode) + "() {\n";
45  resp->String(outtext);
46  outtext = leafNode->host;
47  outtext2 = " this.addWidget(\"text\",\"host\",\"" + outtext + "\");\n";
48  resp->String(outtext2);
49  outtext = leafNode->port;
50  outtext2 = " this.addWidget(\"text\",\"port\",\"" + outtext + "\");\n";
51  resp->String(outtext2);
52  outtext = leafNode->usrName;
53  outtext2 = " this.addWidget(\"text\",\"userName\",\"" + outtext + "\");\n";
54  resp->String(outtext2);
55  outtext = leafNode->passWord;
56  outtext2 = " this.addWidget(\"text\",\"passWord\",\"" + outtext + "\");\n";
57  resp->String(outtext2);
58  resp->String(" this.addOutput(\"data\", \"text\");\n");
59  resp->String(" }\n");
60  outtext = leafNode->dataBaseName + std::to_string(nodeCode);
61  outtext2 =
62  " leafNode" + std::to_string(nodeCode) + ".title = \"mysql_" + outtext + "\";\n";
63  resp->String(outtext2);
64  outtext = " LiteGraph.registerNodeType(\"basic/leafNode" + std::to_string(nodeCode)
65  + "\", leafNode" + std::to_string(nodeCode) + ");\n";
66  resp->String(outtext);
67  resp->String(" var node_leaf" + std::to_string(nodeCode)
68  + " = LiteGraph.createNode(\"basic/leafNode" + std::to_string(nodeCode) + "\");\n");
69 
70  outtext = " node_leaf" + std::to_string(nodeCode) + ".pos = [" + std::to_string(posx) + ","
71  + std::to_string(posy) + "];\n";
72  resp->String(outtext);
73  outtext = " graph.add(node_leaf" + std::to_string(nodeCode) + ");\n";
74  resp->String(outtext);
75 }
77  int posx = 350;
78  int posy = opMapStruct.posy;
79  int nodeCode = opMapStruct.nodeCode;
80  int input_num = opMapStruct.inputNum;
81  std::string outtext;
82  outtext = " function opNode" + std::to_string(nodeCode) + "() {\n";
83  resp->String(outtext);
84  for (int i = 1; i < input_num + 1; i++) {
85  outtext = " this.addInput(\"inputdata_" + std::to_string(i) + "\", \"text\");\n";
86  resp->String(outtext);
87  }
88  outtext = " this.addOutput(\"output_data\", \"text\");}\n";
89  resp->String(outtext);
90  outtext = " opNode" + std::to_string(nodeCode) + ".title = \"opNode\";\n";
91  resp->String(outtext);
92  outtext = " LiteGraph.registerNodeType(\"basic/opNode" + std::to_string(nodeCode)
93  + "\", opNode" + std::to_string(nodeCode) + ");\n";
94  resp->String(outtext);
95  outtext = " var node_op" + std::to_string(nodeCode)
96  + " = LiteGraph.createNode(\"basic/opNode" + std::to_string(nodeCode) + "\");\n";
97  resp->String(outtext);
98  outtext = " node_op" + std::to_string(nodeCode) + ".pos = [" + std::to_string(posx) + ","
99  + std::to_string(posy) + "];\n";
100  resp->String(outtext);
101  outtext = " graph.add(node_op" + std::to_string(nodeCode) + ");\n";
102  resp->String(outtext);
103 }
104 void createFinNode(int posy, int opCodeNow, HttpResp* resp) {
105  int posx = 100 + 2 * 250;
106  std::string outtext;
107  outtext = " function outputNode() {";
108  resp->String(outtext);
109  for (int i = 0; i < opCodeNow; i++) {
110  outtext = " this.addInput(\"outdata" + std::to_string(i) + "\", \"text\");\n";
111  resp->String(outtext);
112  }
113 
114  resp->String("}");
115  outtext = " outputNode.title = \"outputNode\";";
116  resp->String(outtext);
117  outtext = " LiteGraph.registerNodeType(\"basic/outputNode\", outputNode);\n";
118  resp->String(outtext);
119  outtext = " var node_out = LiteGraph.createNode(\"basic/outputNode\");\n";
120  resp->String(outtext);
121  outtext = " node_out.pos = [" + std::to_string(posx) + "," + std::to_string(posy) + "];\n";
122  resp->String(outtext);
123  outtext = " graph.add(node_out);\n";
124  resp->String(outtext);
125 }
126 void Node_leaf_connect(int nodeleftnum, int noderightnum, int nowinputsnum, HttpResp* resp) {
127  std::string outtext;
128  outtext = " node_leaf" + std::to_string(nodeleftnum) + ".connect(0,node_op"
129  + std::to_string(noderightnum) + "," + std::to_string(nowinputsnum) + ");\n";
130  resp->String(outtext);
131 }
132 void Node_op_connect(int nodeleftnum, int nowinputsnum, HttpResp* resp) {
133  std::string outtext;
134  outtext = " node_op" + std::to_string(nodeleftnum) + ".connect(0,node_out,"
135  + std::to_string(nowinputsnum) + ");\n";
136  resp->String(outtext);
137 }
138 
139 void outbaseo(HttpResp* resp) {
140  std::string outtext;
141  outtext = "graph.start();\n";
142  resp->String(outtext);
143  outtext = " </script>\n";
144  resp->String(outtext);
145  outtext = "</body>\n";
146  resp->String(outtext);
147  outtext = "</html>\n";
148  resp->String(outtext);
149 }
150 
151 } // namespace trans
152 } // namespace cb
cb::trans::leafMapStruct::posy
int posy
Definition: api.hpp:52
cb::graph::cbComputeGraph
Definition: cbComputeGraph.hpp:342
cb::trans::createOpNode
void createOpNode(HttpResp *resp, cb::trans::opMapStruct &opMapStruct)
Definition: api.cpp:76
cb::trans::outbaseo
void outbaseo(HttpResp *resp)
Definition: api.cpp:139
cb::trans::createLeafNode
void createLeafNode(HttpResp *resp, cb::trans::leafMapStruct &leafMapStruct, trivial::cbMySqlDevice *leafNode)
Definition: api.cpp:38
cb::trans::createFinNode
void createFinNode(int posy, int opCodeNow, HttpResp *resp)
Definition: api.cpp:104
cb::graph::cbComputeGraph::setVirtualDeviceManager
void setVirtualDeviceManager(trivial::cbVirtualDeviceManager *virtualDeviceM)
Set the Virtual Device Manager object.
Definition: cbComputeGraph.cpp:483
cb::trans::Node_op_connect
void Node_op_connect(int nodeleftnum, int nowinputsnum, HttpResp *resp)
Definition: api.cpp:132
api.hpp
The C plus plus API section.
trivial::cbVirtualDevice::port
std::string port
Definition: cbVirtualDevice.hpp:61
cb::trans::opMapStruct::inputNum
int inputNum
Definition: api.hpp:46
cb::trans::opMapStruct::posy
int posy
Definition: api.hpp:48
cb
_WIN32
Definition: api.cpp:4
cb::graph::cbComputeGraph::execScript
void execScript(const std::string &script)
execute the script
Definition: cbComputeGraph.cpp:578
trivial::cbVirtualDevice::dataBaseName
std::string dataBaseName
Definition: cbVirtualDevice.hpp:66
cb::trans::Node_leaf_connect
void Node_leaf_connect(int nodeleftnum, int noderightnum, int nowinputsnum, HttpResp *resp)
Definition: api.cpp:126
cb::trans::opMapStruct
Definition: api.hpp:43
trivial::cbVirtualDeviceManager
Definition: cbVirtualDevice.hpp:260
cbVirtualDevice.hpp
abstract virtual device. Provide MySql/Redis/Kafka warper. All virtual device will handle the connect...
trivial::cbMySqlDevice
Definition: cbVirtualDevice.hpp:95
cb::trans::outbase
void outbase(HttpResp *resp)
Definition: api.cpp:20
trivial::cbVirtualDevice::host
std::string host
Definition: cbVirtualDevice.hpp:62
cb::trans::leafMapStruct::nodeCode
int nodeCode
Definition: api.hpp:51
trivial::cbVirtualDevice::passWord
std::string passWord
Definition: cbVirtualDevice.hpp:64
trivial::cbVirtualDevice::usrName
std::string usrName
Definition: cbVirtualDevice.hpp:63
cb::trans::opMapStruct::nodeCode
int nodeCode
Definition: api.hpp:44
cb::trans::leafMapStruct
Definition: api.hpp:50
cb::apiCPP::addGraph
cb::graph::cbComputeGraph * addGraph(int32_t idx, const std::string &cmd, trivial::cbVirtualDeviceManager *vdm)
Definition: api.cpp:7