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:
Claudio Maggioni 2016-03-16 10:01:24 +01:00
parent 13db9109d9
commit 66bdc4c21d
4 changed files with 31 additions and 15 deletions

View file

@ -3,8 +3,6 @@
Shell::Commands::Commands(Shell* s) : commands(), threadCommands()
{
parent = s;
if(created) throw CommandsAlreadyCreatedException();
created=true;
}
void Shell::Commands::add(Command* cmd, bool isthread){
@ -25,6 +23,4 @@ int Shell::Commands::launch(const vector<string>* args, bool launchThread){
throw CommandNotFoundException();
}
bool Shell::Commands::created = false;

View file

@ -22,6 +22,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
void setup(Shell *){
void setup(Shell *s){
cout << "Now entering in test shell...\n" << endl;
s->executeCmd("stty -ctlecho");
}

View file

@ -20,11 +20,12 @@ void Shell::setName(const string &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;
name = n;
this->ps = ps;
shellPostSetup = pss;
notLoop = false;
}
@ -60,6 +61,9 @@ void Shell::launch(){
status = executeCmd(args);
delete args;
} while (status);
if(shellPostSetup!=0) {
shellPostSetup(this);
}
}
int Shell::launchCmd(vector<string>* args)
@ -129,6 +133,23 @@ void Shell::EofHandler(int){
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)){
struct sigaction *sa = new struct sigaction();
sa->sa_handler = funcptr;

16
shell.h
View file

@ -29,11 +29,6 @@ class Shell : public CommandExecutor
vector<Command*> commands; //commands that work the same thread of the shell
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:
Commands(Shell*);
void add(Command*, bool isthread=false);
@ -45,6 +40,7 @@ class Shell : public CommandExecutor
string ps;
string name;
void (*shellSetup)(Shell *);
void (*shellPostSetup)(Shell *);
bool notLoop;
int launchCmd(vector<string>* args);
@ -55,21 +51,23 @@ class Shell : public CommandExecutor
class IsUndoingLineException {};
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;
void setPs(const string &value);
string getName() const;
void setName(const string &value);
void launch();
void setShellSetup(void (*)(Shell *));
void (*getShellSetup())(Shell*);
void setShellPostSetup(void (*)(Shell *));
void (*getShellPostSetup())(Shell*);
//for in-shell commands
void addCmd(Command *cmd, bool isThread=false);
size_t howManyCmds() const;
int executeCmd(vector<string>* args);
int executeCmd(const string& args);
//exceptions
class CommandsAlreadyCreatedException{};
//excepsetions
class CommandNotFoundException{};
class ShellLaunchInSetupException{};
};