1
0
Fork 0
This commit is contained in:
Frank Celler 2015-08-12 17:20:35 +02:00
parent 9de6bd39db
commit 4a9d775061
14 changed files with 361 additions and 242 deletions

View File

@ -5,8 +5,7 @@
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
@ -23,14 +22,14 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include "ConsoleThread.h"
#include <iostream>
#include "ApplicationServer/ApplicationServer.h"
#include "Basics/logging.h"
#include "Basics/tri-strings.h"
@ -48,13 +47,26 @@ using namespace triagens::arango;
using namespace arangodb;
using namespace std;
std::atomic<V8LineEditor*> triagens::arango::serverConsole(nullptr);
triagens::basics::Mutex triagens::arango::serverConsoleMutex;
// -----------------------------------------------------------------------------
// --SECTION-- class ConsoleThread
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- static public variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief the line editor object for use in debugging
////////////////////////////////////////////////////////////////////////////////
V8LineEditor* ConsoleThread::serverConsole = nullptr;
////////////////////////////////////////////////////////////////////////////////
/// @brief mutex for console access
////////////////////////////////////////////////////////////////////////////////
Mutex ConsoleThread::serverConsoleMutex;
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
@ -64,7 +76,7 @@ triagens::basics::Mutex triagens::arango::serverConsoleMutex;
////////////////////////////////////////////////////////////////////////////////
ConsoleThread::ConsoleThread (ApplicationServer* applicationServer,
ApplicationV8* applicationV8,
ApplicationV8* applicationV8,
TRI_vocbase_t* vocbase)
: Thread("console"),
_applicationServer(applicationServer),
@ -85,7 +97,7 @@ ConsoleThread::~ConsoleThread () {
}
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// --SECTION-- Thread methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
@ -93,11 +105,12 @@ ConsoleThread::~ConsoleThread () {
////////////////////////////////////////////////////////////////////////////////
void ConsoleThread::run () {
usleep(100000);
usleep(100 * 1000);
// enter V8 context
_context = _applicationV8->enterContext(_vocbase, true);
// work
try {
inner();
}
@ -105,14 +118,15 @@ void ConsoleThread::run () {
}
catch (...) {
_applicationV8->exitContext(_context);
_done = 1;
_done = true;
_applicationServer->beginShutdown();
throw;
}
// exit context
_applicationV8->exitContext(_context);
_done = 1;
_done = true;
_applicationServer->beginShutdown();
}
@ -150,16 +164,16 @@ void ConsoleThread::inner () {
start_pretty_print();
(function () {
var __fs__ = require("fs");
var __rcf__ = __fs__.join(__fs__.home(), ".arangod.rc");
if (__fs__.exists(__rcf__)) {
try {
var __content__ = __fs__.read(__rcf__);
eval(__content__);
}
var __fs__ = require("fs");
var __rcf__ = __fs__.join(__fs__.home(), ".arangod.rc");
if (__fs__.exists(__rcf__)) {
try {
var __content__ = __fs__.read(__rcf__);
eval(__content__);
}
catch (err) {
require("console").log("error in rc file '%s': %s", __rcf__, String(err.stack || err));
}
require("console").log("error in rc file '%s': %s", __rcf__, String(err.stack || err));
}
}
})();
)SCRIPT";
@ -174,7 +188,10 @@ start_pretty_print();
console.open(true);
serverConsole = &console;
{
MUTEX_LOCKER(serverConsoleMutex);
serverConsole = &console;
}
while (! _userAborted) {
if (nrCommands >= gcInterval) {
@ -184,6 +201,7 @@ start_pretty_print();
string input;
bool eof;
{
MUTEX_LOCKER(serverConsoleMutex);
input = console.prompt("arangod> ", "arangod", eof);
@ -222,6 +240,7 @@ start_pretty_print();
}
}
localContext->Exit();
throw "user aborted";
}
@ -229,8 +248,3 @@ start_pretty_print();
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -5,8 +5,7 @@
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
@ -23,46 +22,64 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_REST_SERVER_CONSOLE_THREAD_H
#define ARANGODB_REST_SERVER_CONSOLE_THREAD_H 1
#include "Basics/Common.h"
#include "Basics/Thread.h"
#include "V8/V8LineEditor.h"
#include "V8Server/ApplicationV8.h"
struct TRI_vocbase_t;
// -----------------------------------------------------------------------------
// --SECTION-- forward declarations
// -----------------------------------------------------------------------------
namespace arangodb {
class V8LineEditor;
}
namespace triagens {
namespace rest {
class ApplicationServer;
}
namespace arango {
class ApplicationV8;
// -----------------------------------------------------------------------------
// --SECTION-- class ConsoleThread
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief the line editor object for use in debugging
////////////////////////////////////////////////////////////////////////////////
extern std::atomic<arangodb::V8LineEditor*> serverConsole;
extern triagens::basics::Mutex serverConsoleMutex;
////////////////////////////////////////////////////////////////////////////////
/// @brief ArangoDB server
/// @brief ConsoleThread
////////////////////////////////////////////////////////////////////////////////
class ConsoleThread : public basics::Thread {
private:
ConsoleThread (const ConsoleThread&);
ConsoleThread& operator= (const ConsoleThread&);
ConsoleThread (const ConsoleThread&) = delete;
ConsoleThread& operator= (const ConsoleThread&) = delete;
// -----------------------------------------------------------------------------
// --SECTION-- static public variables
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief the line editor object for use in debugging
////////////////////////////////////////////////////////////////////////////////
static arangodb::V8LineEditor* serverConsole;
////////////////////////////////////////////////////////////////////////////////
/// @brief mutex for console access
////////////////////////////////////////////////////////////////////////////////
static triagens::basics::Mutex serverConsoleMutex;
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
@ -75,8 +92,8 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
ConsoleThread (triagens::rest::ApplicationServer*,
ApplicationV8*,
TRI_vocbase_t*);
ApplicationV8*,
TRI_vocbase_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destructor
@ -84,6 +101,16 @@ namespace triagens {
~ConsoleThread ();
// -----------------------------------------------------------------------------
// --SECTION-- Thread methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief runs the thread
////////////////////////////////////////////////////////////////////////////////
void run () override;
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
@ -95,7 +122,7 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
bool done () const {
return (_done == 1);
return _done;
}
////////////////////////////////////////////////////////////////////////////////
@ -114,14 +141,8 @@ namespace triagens {
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief runs the thread
////////////////////////////////////////////////////////////////////////////////
void run ();
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// --SECTION-- private methods
// -----------------------------------------------------------------------------
private:
@ -138,18 +159,41 @@ namespace triagens {
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief application server
////////////////////////////////////////////////////////////////////////////////
rest::ApplicationServer* _applicationServer;
////////////////////////////////////////////////////////////////////////////////
/// @brief V8 dealer
////////////////////////////////////////////////////////////////////////////////
ApplicationV8* _applicationV8;
////////////////////////////////////////////////////////////////////////////////
/// @brief currently used V8 context
////////////////////////////////////////////////////////////////////////////////
ApplicationV8::V8Context* _context;
////////////////////////////////////////////////////////////////////////////////
/// @brief vocbase
////////////////////////////////////////////////////////////////////////////////
TRI_vocbase_t* _vocbase;
sig_atomic_t _done;
////////////////////////////////////////////////////////////////////////////////
/// @brief done flag
////////////////////////////////////////////////////////////////////////////////
std::atomic<bool> _done;
////////////////////////////////////////////////////////////////////////////////
/// @brief user aborted flag
////////////////////////////////////////////////////////////////////////////////
bool _userAborted;
};
}
}
@ -159,8 +203,3 @@ namespace triagens {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -30,8 +30,6 @@
#ifndef ARANGODB_V8SERVER_APPLICATION_V8_H
#define ARANGODB_V8SERVER_APPLICATION_V8_H 1
#include "Basics/Common.h"
#include "ApplicationServer/ApplicationFeature.h"
#include <v8.h>
@ -163,9 +161,8 @@ namespace triagens {
////////////////////////////////////////////////////////////////////////////////
class ApplicationV8 : public rest::ApplicationFeature {
private:
ApplicationV8 (ApplicationV8 const&) = delete;
ApplicationV8& operator= (ApplicationV8 const&) = delete;
ApplicationV8 (ApplicationV8 const&) = delete;
ApplicationV8& operator= (ApplicationV8 const&) = delete;
// -----------------------------------------------------------------------------
// --SECTION-- public types
@ -678,8 +675,3 @@ namespace triagens {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -639,36 +639,35 @@ static void JS_Debug (const v8::FunctionCallbackInfo<v8::Value>& args) {
debug, args[0]);
}
V8LineEditor* console = triagens::arango::serverConsole.load();
MUTEX_LOCKER(ConsoleThread::serverConsoleMutex);
V8LineEditor* console = ConsoleThread::serverConsole;
if (console != nullptr) {
MUTEX_LOCKER(triagens::arango::serverConsoleMutex);
if (serverConsole.load() != nullptr) {
while (true) {
bool eof;
string input = console->prompt("debug> ", "debug", eof);
while (true) {
bool eof;
string input = console->prompt("debug> ", "debug", eof);
if (eof) {
break;
}
if (eof) {
break;
}
if (input.empty()) {
continue;
}
if (input.empty()) {
continue;
}
console->addHistory(input);
console->addHistory(input);
{
v8::TryCatch tryCatch;
v8::HandleScope scope(isolate);
{
v8::TryCatch tryCatch;
v8::HandleScope scope(isolate);
TRI_ExecuteJavaScriptString(isolate, isolate->GetCurrentContext(),
TRI_V8_STRING(input.c_str()), name, true);
TRI_ExecuteJavaScriptString(isolate, isolate->GetCurrentContext(),
TRI_V8_STRING(input.c_str()), name, true);
if (tryCatch.HasCaught()) {
std::cout << TRI_StringifyV8Exception(isolate, &tryCatch);
}
}
if (tryCatch.HasCaught()) {
std::cout << TRI_StringifyV8Exception(isolate, &tryCatch);
}
}
}
}

View File

@ -1,12 +1,11 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief a basis class which defines the methods for determining
/// when an input is "complete"
/// @brief a basis class to define when an input is "complete"
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
@ -24,7 +23,7 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Esteban Lombeyda
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
@ -35,6 +34,14 @@
namespace arangodb {
// -----------------------------------------------------------------------------
// --SECTION-- class Completer
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief Completer
////////////////////////////////////////////////////////////////////////////////
class Completer {
// -----------------------------------------------------------------------------
@ -43,9 +50,17 @@ namespace arangodb {
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief constructor
////////////////////////////////////////////////////////////////////////////////
Completer () {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destructor
////////////////////////////////////////////////////////////////////////////////
virtual ~Completer () {
}
@ -59,16 +74,13 @@ namespace arangodb {
/// @brief check if line is complete
////////////////////////////////////////////////////////////////////////////////
virtual bool isComplete (std::string const&,
size_t lineno) = 0;
virtual bool isComplete (std::string const&, size_t lineno) = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief computes all strings which begins with the given text
////////////////////////////////////////////////////////////////////////////////
virtual void getAlternatives (char const*,
std::vector<std::string>&) = 0;
virtual std::vector<std::string> alternatives (char const*) = 0;
};
}
@ -77,8 +89,3 @@ namespace arangodb {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -23,6 +23,7 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Jan Steemann
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
@ -61,7 +62,7 @@ static char* CompletionGenerator (char const* text, int state) {
// compute the possible completion
if (state == 0) {
COMPLETER->getAlternatives(text, result);
result = COMPLETER->alternatives(text);
LineEditor::sortAlternatives(result);
}
@ -205,6 +206,15 @@ ReadlineShell::~ReadlineShell () {
// --SECTION-- ShellImplementation methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief handle a signal
////////////////////////////////////////////////////////////////////////////////
void ReadlineShell::signal () {
// set the global state, so the readline input loop can react on it
setLoopState(2);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief line editor open
////////////////////////////////////////////////////////////////////////////////
@ -261,12 +271,12 @@ bool ReadlineShell::close () {
bool res = writeHistory();
clear_history();
#ifndef __APPLE__
HIST_ENTRY** hist = history_list();
if (hist != nullptr) {
TRI_SystemFree(hist);
}
#endif
return res;
}
@ -369,15 +379,6 @@ string ReadlineShell::getLine (const string& prompt, bool& eof) {
return _lastInput;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief handle a signal
////////////////////////////////////////////////////////////////////////////////
void ReadlineShell::signal () {
// set the global state, so the readline input loop can react on it
setLoopState(2);
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -5,7 +5,7 @@
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
@ -42,6 +42,20 @@ namespace arangodb {
class ReadlineShell : public ShellImplementation {
// -----------------------------------------------------------------------------
// --SECTION-- static public methods
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief return the currently active shell instance
////////////////////////////////////////////////////////////////////////////////
static ReadlineShell* instance () {
return _instance.load();
}
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
@ -111,20 +125,6 @@ namespace arangodb {
void signal () override final;
// -----------------------------------------------------------------------------
// --SECTION-- static public methods
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief return the currently active shell instance
////////////////////////////////////////////////////////////////////////////////
static ReadlineShell* instance () {
return _instance.load();
}
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
@ -185,7 +185,6 @@ namespace arangodb {
static std::atomic<ReadlineShell*> _instance;
};
}
#endif

View File

@ -1,12 +1,11 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief a basis class which defines the methods for determining
/// when an input is "complete"
/// @brief shell factory
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
@ -24,7 +23,7 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Esteban Lombeyda
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
@ -43,6 +42,18 @@
using namespace triagens;
using namespace arangodb;
// -----------------------------------------------------------------------------
// --SECTION-- class ShellImplFactory
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- static public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a shell
////////////////////////////////////////////////////////////////////////////////
ShellImplementation* ShellImplFactory::buildShell (std::string const& history,
Completer* completer) {
#ifdef _WIN32
@ -58,6 +69,10 @@ ShellImplementation* ShellImplFactory::buildShell (std::string const& history,
#endif
}
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not the shell will have a CTRL-C handler
////////////////////////////////////////////////////////////////////////////////
bool ShellImplFactory::hasCtrlCHandler () {
#ifdef _WIN32
// under Windows the readline is not compilable
@ -74,8 +89,3 @@ bool ShellImplFactory::hasCtrlCHandler () {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -1,12 +1,11 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief a basis class which defines the methods for determining
/// when an input is "complete"
/// @brief shell factory
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
@ -24,7 +23,7 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Esteban Lombeyda
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
@ -33,13 +32,30 @@
#include "Basics/Common.h"
// -----------------------------------------------------------------------------
// --SECTION-- forward declarations
// -----------------------------------------------------------------------------
namespace arangodb {
class ShellImplementation;
class Completer;
}
namespace triagens {
// -----------------------------------------------------------------------------
// --SECTION-- class ShellImplFactory
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief ShellImplFactory
////////////////////////////////////////////////////////////////////////////////
class ShellImplFactory {
ShellImplFactory () = delete;
ShellImplFactory (const ShellImplFactory&) = delete;
ShellImplFactory& operator= (const ShellImplFactory&) = delete;
// -----------------------------------------------------------------------------
// --SECTION-- static public methods
// -----------------------------------------------------------------------------
public:
@ -47,22 +63,19 @@ namespace triagens {
/// @brief creates a shell
////////////////////////////////////////////////////////////////////////////////
static arangodb::ShellImplementation* buildShell (std::string const& history, arangodb::Completer*);
static ShellImplementation* buildShell (std::string const& history,
Completer*);
////////////////////////////////////////////////////////////////////////////////
/// @brief whether or not the shell will have a CTRL-C handler
////////////////////////////////////////////////////////////////////////////////
static bool hasCtrlCHandler ();
static bool hasCtrlCHandler ();
};
}
#endif
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -66,6 +66,18 @@ ShellImplementation::ShellImplementation (string const& history,
ShellImplementation::~ShellImplementation () {
}
// -----------------------------------------------------------------------------
// --SECTION-- virtual public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief handle a signal
////////////////////////////////////////////////////////////////////////////////
void ShellImplementation::signal () {
// do nothing special
}
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
@ -147,14 +159,6 @@ string ShellImplementation::prompt (const string& prompt,
return line;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief handle a signal
////////////////////////////////////////////////////////////////////////////////
void ShellImplementation::signal () {
// do nothing special
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -33,6 +33,10 @@
#include "Basics/Common.h"
// -----------------------------------------------------------------------------
// --SECTION-- forward declarations
// -----------------------------------------------------------------------------
namespace arangodb {
class Completer;
@ -96,6 +100,12 @@ namespace arangodb {
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief handle a signal
////////////////////////////////////////////////////////////////////////////////
virtual void signal ();
////////////////////////////////////////////////////////////////////////////////
/// @brief line editor open
////////////////////////////////////////////////////////////////////////////////
@ -135,12 +145,6 @@ namespace arangodb {
virtual std::string getLine (const std::string& prompt, bool& eof) = 0;
////////////////////////////////////////////////////////////////////////////////
/// @brief handle a signal
////////////////////////////////////////////////////////////////////////////////
virtual void signal ();
// -----------------------------------------------------------------------------
// --SECTION-- protected variables
// -----------------------------------------------------------------------------

View File

@ -6,7 +6,6 @@
/// DISCLAIMER
///
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
@ -47,6 +46,7 @@ using namespace arangodb;
////////////////////////////////////////////////////////////////////////////////
#ifndef _WIN32
static void SignalHandler (int signal) {
// get the instance of the console
auto instance = V8LineEditor::instance();
@ -55,12 +55,21 @@ static void SignalHandler (int signal) {
instance->signal();
}
}
#endif
// -----------------------------------------------------------------------------
// --SECTION-- class V8Completer
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- Completer methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////
bool V8Completer::isComplete (std::string const& source, size_t lineno) {
int openParen = 0;
int openBrackets = 0;
@ -68,9 +77,23 @@ bool V8Completer::isComplete (std::string const& source, size_t lineno) {
int openStrings = 0; // only used for template strings, which can be multi-line
int openComments = 0;
enum line_parse_state_e {
NORMAL, // start
NORMAL_1, // from NORMAL: seen a single /
DOUBLE_QUOTE, // from NORMAL: seen a single "
DOUBLE_QUOTE_ESC, // from DOUBLE_QUOTE: seen a backslash
SINGLE_QUOTE, // from NORMAL: seen a single '
SINGLE_QUOTE_ESC, // from SINGLE_QUOTE: seen a backslash
BACKTICK, // from NORMAL: seen a single `
BACKTICK_ESC, // from BACKTICK: seen a backslash
MULTI_COMMENT, // from NORMAL_1: seen a *
MULTI_COMMENT_1, // from MULTI_COMMENT, seen a *
SINGLE_COMMENT // from NORMAL_1; seen a /
};
char const* ptr = source.c_str();
char const* end = ptr + source.length();
LineParseState state = NORMAL;
line_parse_state_e state = NORMAL;
while (ptr < end) {
if (state == DOUBLE_QUOTE) {
@ -214,11 +237,12 @@ bool V8Completer::isComplete (std::string const& source, size_t lineno) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief computes all strings which begins with the given text
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////
void V8Completer::getAlternatives (char const * text,
std::vector<std::string>& result) {
vector<string> V8Completer::alternatives (char const * text) {
vector<string> result;
// locate global object or sub-object
v8::Isolate* isolate = v8::Isolate::GetCurrent();
@ -236,14 +260,14 @@ void V8Completer::getAlternatives (char const * text,
if (! current->Has(name)) {
TRI_DestroyVectorString(&splitted);
return;
return result;
}
v8::Handle<v8::Value> val = current->Get(name);
if (! val->IsObject()) {
TRI_DestroyVectorString(&splitted);
return;
return result;
}
current = val->ToObject();
@ -319,12 +343,21 @@ void V8Completer::getAlternatives (char const * text,
}
TRI_FreeString(TRI_CORE_MEM_ZONE, prefix);
return result;
}
// -----------------------------------------------------------------------------
// --SECTION-- class V8LineEditor
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- static private variables
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief the active instance of the editor
////////////////////////////////////////////////////////////////////////////////
std::atomic<V8LineEditor*> V8LineEditor::_instance(nullptr);
// -----------------------------------------------------------------------------
@ -342,7 +375,6 @@ V8LineEditor::V8LineEditor (v8::Handle<v8::Context> context,
_completer(V8Completer()) {
// register global instance
TRI_ASSERT(_instance.load() == nullptr);
_instance.store(this);
@ -359,6 +391,10 @@ V8LineEditor::~V8LineEditor () {
_instance.store(nullptr);
}
// -----------------------------------------------------------------------------
// --SECTION-- static protected methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief setup a signal handler for CTRL-C
////////////////////////////////////////////////////////////////////////////////
@ -391,8 +427,3 @@ void V8LineEditor::initializeShell () {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -5,8 +5,7 @@
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
/// Copyright 2014-2015 ArangoDB GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
@ -23,60 +22,67 @@
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2014-2015, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_V8_V8LINE_EDITOR_H
#define ARANGODB_V8_V8LINE_EDITOR_H 1
#include "Basics/Common.h"
#include "Utilities/LineEditor.h"
#include "Utilities/Completer.h"
#include <v8.h>
namespace arangodb {
// -----------------------------------------------------------------------------
// --SECTION-- class V8Completer
// -----------------------------------------------------------------------------
namespace arangodb {
////////////////////////////////////////////////////////////////////////////////
/// @brief V8Completer
////////////////////////////////////////////////////////////////////////////////
class V8Completer : public Completer {
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief constructor
////////////////////////////////////////////////////////////////////////////////
V8Completer () {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destructor
////////////////////////////////////////////////////////////////////////////////
~V8Completer () {
}
// -----------------------------------------------------------------------------
// --SECTION-- Completer methods
// -----------------------------------------------------------------------------
public:
bool isComplete (std::string const&,
size_t lineno) override final;
////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////
void getAlternatives (char const*,
std::vector<std::string>&) override final;
bool isComplete (std::string const&, size_t lineno) override final;
private:
enum LineParseState {
NORMAL, // start
NORMAL_1, // from NORMAL: seen a single /
DOUBLE_QUOTE, // from NORMAL: seen a single "
DOUBLE_QUOTE_ESC, // from DOUBLE_QUOTE: seen a backslash
SINGLE_QUOTE, // from NORMAL: seen a single '
SINGLE_QUOTE_ESC, // from SINGLE_QUOTE: seen a backslash
BACKTICK, // from NORMAL: seen a single `
BACKTICK_ESC, // from BACKTICK: seen a backslash
MULTI_COMMENT, // from NORMAL_1: seen a *
MULTI_COMMENT_1, // from MULTI_COMMENT, seen a *
SINGLE_COMMENT // from NORMAL_1; seen a /
};
////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> alternatives (char const*) override final;
};
// -----------------------------------------------------------------------------
@ -84,11 +90,10 @@ namespace arangodb {
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief line editor
/// @brief V8LineEditor
////////////////////////////////////////////////////////////////////////////////
class V8LineEditor : public LineEditor {
V8LineEditor (LineEditor const&) = delete;
V8LineEditor& operator= (LineEditor const&) = delete;
@ -111,6 +116,12 @@ namespace arangodb {
~V8LineEditor ();
// -----------------------------------------------------------------------------
// --SECTION-- static public methods
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief the global instance of the editor
////////////////////////////////////////////////////////////////////////////////
@ -120,23 +131,41 @@ namespace arangodb {
}
// -----------------------------------------------------------------------------
// --SECTION-- protected methods
// --SECTION-- static protected methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a concrete Shell with the correct parameter (Completer!!)
////////////////////////////////////////////////////////////////////////////////
protected:
void initializeShell () override;
////////////////////////////////////////////////////////////////////////////////
/// @brief setup a signal handler for CTRL-C
////////////////////////////////////////////////////////////////////////////////
static void setupCtrlCHandler ();
// -----------------------------------------------------------------------------
// --SECTION-- protected methods
// -----------------------------------------------------------------------------
protected:
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a concrete Shell with the correct completer
////////////////////////////////////////////////////////////////////////////////
void initializeShell () override;
// -----------------------------------------------------------------------------
// --SECTION-- static private variables
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief the active instance of the editor
////////////////////////////////////////////////////////////////////////////////
static std::atomic<V8LineEditor*> _instance;
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
@ -154,14 +183,7 @@ namespace arangodb {
////////////////////////////////////////////////////////////////////////////////
V8Completer _completer;
////////////////////////////////////////////////////////////////////////////////
/// @brief the active instance of the editor
////////////////////////////////////////////////////////////////////////////////
static std::atomic<V8LineEditor*> _instance;
};
}
#endif
@ -169,8 +191,3 @@ namespace arangodb {
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -236,12 +236,6 @@ sub formatFile ($$$) {
$line = '/// @author Dr. Oreste Costa-Panaia';
}
if ($line =~ /^\/\/ outline-regexp:/) {
if ($isJavaScript == 1) {
$line = '// outline-regexp: "/// @brief\\\\|/// @addtogroup\\\\|/// @page\\\\|/// @startDocuBlock\\\\|// --SECTION--\\\\|/// @\\\\}\\\\|/\\\\*jslint"';
}
}
if ($line =~ /^[ \t]*(\/\/\/.*)$/) {
$line = "$1";
}
@ -387,11 +381,6 @@ sub formatFile ($$$) {
print $out "// -----------------------------------------------------------------------------\n";
print $out "// --SECTION-- END-OF-FILE\n";
print $out "// -----------------------------------------------------------------------------\n";
print $out "\n";
print $out "// Local Variables:\n";
print $out "// mode: outline-minor\n";
print $out "// outline-regexp: \"/// \@brief\\\\|/// {\@inheritDoc}\\\\|/// \@page\\\\|/// \@startDocuBlock\\\\|// --SECTION--\\\\|/// \@\\\\}\"\n";
print $out "// End:\n";
if (! $dryRun) {
close($out)