Removed commands lock for one object. Added possibility to add postSetup on the shell. Added getters and setters for
the setup and the postSetup.
This commit is contained in:
parent
13db9109d9
commit
66bdc4c21d
4 changed files with 31 additions and 15 deletions
|
@ -3,8 +3,6 @@
|
||||||
Shell::Commands::Commands(Shell* s) : commands(), threadCommands()
|
Shell::Commands::Commands(Shell* s) : commands(), threadCommands()
|
||||||
{
|
{
|
||||||
parent = s;
|
parent = s;
|
||||||
if(created) throw CommandsAlreadyCreatedException();
|
|
||||||
created=true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shell::Commands::add(Command* cmd, bool isthread){
|
void Shell::Commands::add(Command* cmd, bool isthread){
|
||||||
|
@ -25,6 +23,4 @@ int Shell::Commands::launch(const vector<string>* args, bool launchThread){
|
||||||
throw CommandNotFoundException();
|
throw CommandNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Shell::Commands::created = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
3
main.cpp
3
main.cpp
|
@ -22,6 +22,7 @@ int main(int argc, char **argv)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(Shell *){
|
void setup(Shell *s){
|
||||||
cout << "Now entering in test shell...\n" << endl;
|
cout << "Now entering in test shell...\n" << endl;
|
||||||
|
s->executeCmd("stty -ctlecho");
|
||||||
}
|
}
|
||||||
|
|
23
shell.cpp
23
shell.cpp
|
@ -20,11 +20,12 @@ void Shell::setName(const string &value)
|
||||||
name = value;
|
name = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shell::Shell( string n, string ps,void (*s)(Shell*)) : cmds(this)
|
Shell::Shell( string n, string ps,void (*s)(Shell*), void (*pss)(Shell*)) : cmds(this)
|
||||||
{
|
{
|
||||||
shellSetup = s;
|
shellSetup = s;
|
||||||
name = n;
|
name = n;
|
||||||
this->ps = ps;
|
this->ps = ps;
|
||||||
|
shellPostSetup = pss;
|
||||||
notLoop = false;
|
notLoop = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +61,9 @@ void Shell::launch(){
|
||||||
status = executeCmd(args);
|
status = executeCmd(args);
|
||||||
delete args;
|
delete args;
|
||||||
} while (status);
|
} while (status);
|
||||||
|
if(shellPostSetup!=0) {
|
||||||
|
shellPostSetup(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Shell::launchCmd(vector<string>* args)
|
int Shell::launchCmd(vector<string>* args)
|
||||||
|
@ -129,6 +133,23 @@ void Shell::EofHandler(int){
|
||||||
undoingLine = true;
|
undoingLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shell::setShellSetup(void (*s)(Shell *)){
|
||||||
|
shellSetup=s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*Shell::getShellSetup())(Shell*) {
|
||||||
|
return shellSetup;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shell::setShellPostSetup(void (*s)(Shell *)){
|
||||||
|
shellPostSetup=s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*Shell::getShellPostSetup())(Shell*) {
|
||||||
|
return shellPostSetup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void setEofHandler(void (*funcptr)(int)){
|
void setEofHandler(void (*funcptr)(int)){
|
||||||
struct sigaction *sa = new struct sigaction();
|
struct sigaction *sa = new struct sigaction();
|
||||||
sa->sa_handler = funcptr;
|
sa->sa_handler = funcptr;
|
||||||
|
|
16
shell.h
16
shell.h
|
@ -29,11 +29,6 @@ class Shell : public CommandExecutor
|
||||||
vector<Command*> commands; //commands that work the same thread of the shell
|
vector<Command*> commands; //commands that work the same thread of the shell
|
||||||
vector<Command*> threadCommands; //commands that work on a different thread
|
vector<Command*> threadCommands; //commands that work on a different thread
|
||||||
|
|
||||||
//just one instance of the object
|
|
||||||
static bool created;
|
|
||||||
Commands(const Commands&);
|
|
||||||
Commands operator=(const Commands&);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Commands(Shell*);
|
Commands(Shell*);
|
||||||
void add(Command*, bool isthread=false);
|
void add(Command*, bool isthread=false);
|
||||||
|
@ -45,6 +40,7 @@ class Shell : public CommandExecutor
|
||||||
string ps;
|
string ps;
|
||||||
string name;
|
string name;
|
||||||
void (*shellSetup)(Shell *);
|
void (*shellSetup)(Shell *);
|
||||||
|
void (*shellPostSetup)(Shell *);
|
||||||
bool notLoop;
|
bool notLoop;
|
||||||
|
|
||||||
int launchCmd(vector<string>* args);
|
int launchCmd(vector<string>* args);
|
||||||
|
@ -55,21 +51,23 @@ class Shell : public CommandExecutor
|
||||||
class IsUndoingLineException {};
|
class IsUndoingLineException {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Shell(string n="msh", string ps="MSH$", void (*s)(Shell*)=0);
|
Shell(string n="msh", string ps="MSH$", void (*s)(Shell*)=0, void (*pss)(Shell*)=0);
|
||||||
string getPs() const;
|
string getPs() const;
|
||||||
void setPs(const string &value);
|
void setPs(const string &value);
|
||||||
string getName() const;
|
string getName() const;
|
||||||
void setName(const string &value);
|
void setName(const string &value);
|
||||||
void launch();
|
void launch();
|
||||||
|
void setShellSetup(void (*)(Shell *));
|
||||||
|
void (*getShellSetup())(Shell*);
|
||||||
|
void setShellPostSetup(void (*)(Shell *));
|
||||||
|
void (*getShellPostSetup())(Shell*);
|
||||||
//for in-shell commands
|
//for in-shell commands
|
||||||
void addCmd(Command *cmd, bool isThread=false);
|
void addCmd(Command *cmd, bool isThread=false);
|
||||||
size_t howManyCmds() const;
|
size_t howManyCmds() const;
|
||||||
int executeCmd(vector<string>* args);
|
int executeCmd(vector<string>* args);
|
||||||
int executeCmd(const string& args);
|
int executeCmd(const string& args);
|
||||||
|
|
||||||
//exceptions
|
//excepsetions
|
||||||
class CommandsAlreadyCreatedException{};
|
|
||||||
class CommandNotFoundException{};
|
class CommandNotFoundException{};
|
||||||
class ShellLaunchInSetupException{};
|
class ShellLaunchInSetupException{};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue