summaryrefslogtreecommitdiffstats
path: root/src/madc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/madc.cpp')
-rw-r--r--src/madc.cpp75
1 files changed, 32 insertions, 43 deletions
diff --git a/src/madc.cpp b/src/madc.cpp
index 106617c..a902144 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -17,11 +17,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "Net/FdManager.h"
-#include "Net/IPAddress.h"
#include "Net/ThreadManager.h"
#include "Common/ClientConnection.h"
#include "Common/ConfigManager.h"
+#include "Common/Requests/IdentifyRequest.h"
#include "Common/Logger.h"
#include "Common/RequestManager.h"
#include "Client/CommandParser.h"
@@ -35,37 +34,14 @@
using namespace Mad;
-static void usage(const std::string &cmd) {
- std::cerr << "Usage: " << cmd << " address[:port]" << std::endl;
-}
-
-static void handleCommand(char *cmd) {
- if(!cmd)
- Client::CommandParser::get()->requestDisconnect();
- else if(!*cmd)
- return;
- else {
- Client::CommandParser::get()->parse(cmd);
- add_history(cmd);
- }
-
- if(Client::CommandManager::get()->requestsActive()) {
- rl_callback_handler_remove();
- Net::FdManager::get()->setFdEvents(STDIN_FILENO, 0);
- }
-}
+static bool commandRunning = false;
-static void charHandler(short events) {
- if(events & POLLIN)
- rl_callback_read_char();
+static void usage(const std::string &cmd) {
+ std::cerr << "Usage: " << cmd << " address" << std::endl;
}
-static void activateReadline() {
- if(Client::CommandManager::get()->willDisconnect())
- return;
-
- rl_callback_handler_install("mad> ", handleCommand);
- Net::FdManager::get()->setFdEvents(STDIN_FILENO, POLLIN);
+static void commandFinished() {
+ commandRunning = false;
}
int main(int argc, char *argv[]) {
@@ -82,17 +58,22 @@ int main(int argc, char *argv[]) {
Common::ClientConnection *connection = new Common::ClientConnection;
try {
- connection->connect(Net::IPAddress(argv[1]));
+ connection->connect(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(argv[1]), 6666));
std::cerr << "Connecting to " << argv[1] << "..." << std::flush;
while(connection->isConnecting())
usleep(100000);
- std::cerr << " connected." << std::endl;
-
Common::RequestManager::get()->registerConnection(connection);
+ commandRunning = true;
+ Common::RequestManager::get()->sendRequest<Common::Requests::IdentifyRequest>(connection, boost::bind(&commandFinished));
+ while(commandRunning) {
+ usleep(100000);
+ }
+
+ std::cerr << " connected." << std::endl;
std::cerr << "Receiving host list..." << std::flush;
Client::InformationManager::get()->updateDaemonList(connection);
@@ -103,16 +84,24 @@ int main(int argc, char *argv[]) {
std::cerr << " done." << std::endl << std::endl;
Client::CommandParser::get()->setConnection(connection);
- Client::CommandManager::get()->signalFinished().connect(&activateReadline);
-
- Net::FdManager::get()->registerFd(STDIN_FILENO,&charHandler);
-
- activateReadline();
-
- while(connection->isConnected())
- usleep(100000);
-
- Net::FdManager::get()->unregisterFd(STDIN_FILENO);
+ Client::CommandManager::get()->signalFinished().connect(&commandFinished);
+
+ while(connection->isConnected()) {
+ char *cmd = readline("mad> ");
+
+ if(!cmd) {
+ commandRunning = true;
+ Client::CommandParser::get()->requestDisconnect();
+ }
+ else if(*cmd) {
+ commandRunning = true;
+ Client::CommandParser::get()->parse(cmd);
+ add_history(cmd);
+ }
+
+ while(Client::CommandManager::get()->requestsActive())
+ usleep(100000);
+ }
Common::RequestManager::get()->unregisterConnection(connection);
}