Minsky
RESTService.cc File Reference
#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
 Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state changes.
 

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 96 of file RESTService.cc.

References processBuffer(), and rminsky.

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

◆ processBuffer()

void processBuffer ( const string &  buffer)

Definition at line 56 of file RESTService.cc.

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

Referenced by main().

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

◆ toREST()

string toREST ( string  x)

Definition at line 50 of file RESTService.cc.

Referenced by processBuffer().

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

Variable Documentation

◆ rminsky

RESTMinsky rminsky

Definition at line 33 of file RESTService.cc.

Referenced by main(), and processBuffer().