Minsky: 3.17.0
RESTService.cc File Reference
#include "variableInstanceList.h"
#include "RESTMinsky.h"
#include "cairoItems.h"
#include "minsky_epilogue.h"
Include dependency graph for RESTService.cc:

Go to the source code of this file.

Namespaces

 minsky
 

Functions

Minsky & minsky::minsky ()
 global minsky object More...
 
void minsky::doOneEvent (bool idleTasksOnly)
 checks if any GUI events are waiting, and proces an event if so More...
 
string toREST (string x)
 
void processBuffer (const string &buffer)
 
int main (int argc, const char *argv[])
 

Variables

RESTMinsky rminsky
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 97 of file RESTService.cc.

References processBuffer(), and rminsky.

98 {
99  const LocalMinsky lm(rminsky);
100  const bool batch=argc>1 && argv[1]==string("-batch");
101 
102 
103  char* c;
104  string buffer;
105 
106 #ifdef READLINE
107  if (batch)
108  while (getline(cin,buffer))
109  processBuffer(buffer);
110  else // interactive, use readline
111  while ((c=readline("cmd>"))!=nullptr)
112  {
113  const string buffer=c;
114  processBuffer(buffer);
115  if (strlen(c)) add_history(c);
116  free(c);
117  }
118 #else
119  while (getline(cin,buffer))
120  processBuffer(buffer);
121 #endif
122 }
void processBuffer(const string &buffer)
Definition: RESTService.cc:57
RAII set the minsky object to a different one for the current scope.
Definition: minsky.h:540
RESTMinsky rminsky
Definition: RESTService.cc:34
Here is the call graph for this function:

◆ processBuffer()

void processBuffer ( const string &  buffer)

Definition at line 57 of file RESTService.cc.

References minsky::RESTMinsky::commandHook(), minsky::RESTMinsky::registry, rminsky, and toREST().

Referenced by main().

58 {
59  if (buffer[0]=='#') return;
60  if (buffer[0]!='/')
61  {
62  cerr << buffer << "command doesn't starts with /"<<endl;
63  return;
64  }
65  if (buffer=="/list")
66  {
67  for (auto& i: rminsky.registry)
68  cout << toREST(i.first) << endl;
69  return;
70  }
71 
72  try
73  {
74  auto n=buffer.find(' ');
75  json_pack_t jin(json5_parser::mValue::null);
76  string cmd;
77  if (n==string::npos)
78  cmd=buffer;
79  else
80  { // read argument(s)
81  cmd=buffer.substr(0,n);
82  read(buffer.substr(n),jin);
83  }
84  cout<<cmd<<"=>";
85  cmd.erase(0,1); // remove leading '/'
86  replace(cmd.begin(), cmd.end(), '/', '.');
87  write(rminsky.registry.process(cmd, jin)->asBuffer(),cout);
88  cout << endl;
89  rminsky.commandHook(cmd, jin);
90  }
91  catch (const std::exception& ex)
92  {
93  cerr << "Exception: "<<ex.what() << endl;
94  }
95 }
void commandHook(const std::string &command, const RP &args)
Definition: RESTMinsky.h:32
RESTProcess_t registry
Definition: RESTMinsky.h:29
string toREST(string x)
Definition: RESTService.cc:51
RESTMinsky rminsky
Definition: RESTService.cc:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toREST()

string toREST ( string  x)

Definition at line 51 of file RESTService.cc.

Referenced by processBuffer().

52 {
53  replace(x.begin(),x.end(),'.','/');
54  return '/'+x;
55 }
Here is the caller graph for this function:

Variable Documentation

◆ rminsky

RESTMinsky rminsky

Definition at line 34 of file RESTService.cc.

Referenced by main(), and processBuffer().