Commit 4569bf50 authored by Nicolas Jager's avatar Nicolas Jager

console : add commands to query/order the daemon

- get all active calls.
- kill call.
- switch the debug output in the client console.

Change-Id: Ie00fa5366c886ff1570d6879288fea62b98e823d
Tuleap: #1289
parent 85e1231f
......@@ -21,6 +21,7 @@
using namespace RingClientUWP;
using namespace RingClientUWP::Views;
using namespace RingClientUWP::ViewModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml::Documents;
......@@ -88,26 +89,87 @@ void RingConsolePanel::_sendDbgCmd__KeyDown(Platform::Object^ sender, Windows::U
/*\ ADD EACH NEW COMMAND TO THE HELP LIST \*/
void RingConsolePanel::sendCommand()
{
auto cmdInput = _tBoxDbg_->Text;
auto inputConst_str = Utils::toString(_tBoxDbg_->Text);
if (inputConst_str.empty())
return;
auto inputConst_cstr = inputConst_str.c_str();
char* input_cstr = _strdup(inputConst_cstr); // full string
char* input_cstr_nextToken; // tokenized string
char* cmd_cstr = strtok_s(input_cstr, " ", &input_cstr_nextToken);
char* parameter1_cstr = strtok_s(input_cstr_nextToken, " ", &input_cstr_nextToken);
// parameter2...
if (!cmd_cstr)
return;
std::string input(cmd_cstr);
std::string parameter1;
if (parameter1_cstr)
parameter1 = parameter1_cstr;
free(input_cstr);
free(input_cstr_nextToken);
//free((char*)inputConst_cstr);
addCommandToHistory();
historyLevel++;
_tBoxDbg_->Text = "";
currentCmd = "";
historyLevel = historyCmds.Size;
if (cmdInput->IsEmpty()) {
return;
}
else if (cmdInput == "help") {
if (input == "help") {
MSG_(">> Help :");
MSG_("use PgUp/PgDown for crawling commands history.");
MSG_("getCallsList, switchDebug, killCall [callId, -all], getAccountInfo, getContactsList, placeCall [contact name]");
return;
}
else if (input == "getCallsList") {
RingD::instance->getCallsList();
return;
}
else if (input == "switchDebug") {
MSG_(">> switching dameon debug output");
RingD::instance->switchDebug();
return;
}
else if (input == "killCall") {
if (parameter1.empty()) {
MSG_("callId missing");
return;
}
RingD::instance->killCall(Utils::toPlatformString(parameter1));
return;
}
else if (input == "getAccountInfo") {
auto id = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
MSG_("id : "+Utils::toString(id));
return;
}
else if (input == "getContactsList") {
auto list = ContactsViewModel::instance->contactsList;
MSG_("list of calls returned by the daemon :");
for (auto contact : list) {
MSG_("name : " + Utils::toString(contact->name_));
MSG_("ringId : " + Utils::toString(contact->ringID_));
}
return;
}
else if (input == "placeCall") {
if (parameter1.empty()) {
MSG_("contact name missing");
return;
}
auto contact = ContactsViewModel::instance->findContactByName(Utils::toPlatformString(parameter1));
if (!contact) {
MSG_("contact "+parameter1+" not found");
return;
}
RingD::instance->placeCall(contact);
}
std::wstring wStr(cmdInput->Begin());
std::string result(wStr.begin(), wStr.end());
MSG_(">> error, command \'" + result + "\' not found");
MSG_(">> error, command \'" + input + "\' not found");
}
void RingConsolePanel::addCommandToHistory()
......
......@@ -366,6 +366,10 @@ void RingClientUWP::RingD::registerThisDevice(String ^ pin, String ^ archivePass
void
RingClientUWP::RingD::startDaemon()
{
if (daemonRunning) {
ERR_("daemon already runnging");
return;
}
//eraseCacheFolder();
editModeOn_ = true;
......@@ -424,7 +428,6 @@ RingClientUWP::RingD::startDaemon()
if (state3 == CallStatus::ENDED)
DRing::hangUp(callId); // solve a bug in the daemon API.
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::High, ref new DispatchedHandler([=]()
{
......@@ -517,8 +520,9 @@ RingClientUWP::RingD::startDaemon()
}),
DRing::exportable_callback<DRing::Debug::MessageSend>([&](const std::string& toto)
{
dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([=]() {
if (debugModeOn_)
dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([=]() {
RingDebug::instance->print(toto);
}));
}),
......@@ -666,9 +670,9 @@ RingClientUWP::RingD::startDaemon()
DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_CONSOLE_LOG |
DRing::DRING_FLAG_DEBUG));
daemonRunning_ = DRing::start();
if (!DRing::start()) {
if (!daemonRunning_) {
ERR_("\ndaemon didn't start.\n");
return;
}
......@@ -704,7 +708,7 @@ RingClientUWP::RingD::startDaemon()
});
while (true) {
while (daemonRunning) {
DRing::pollEvents();
dequeueTasks();
Sleep(5);
......@@ -804,6 +808,7 @@ RingD::dequeueTasks()
deviceDetails.insert(std::make_pair(DRing::Account::ConfProperties::ARCHIVE_PASSWORD, password));
DRing::addAccount(deviceDetails);
}
break;
case Request::GetKnownDevices:
{
auto accountId = task->_accountId;
......@@ -852,6 +857,28 @@ RingD::dequeueTasks()
DRing::removeAccount(accountId2);
break;
}
case Request::GetCallsList:
{
auto callsList = DRing::getCallList();
MSG_("list of calls returned by the daemon :");
for (auto call : callsList)
MSG_(call);
MSG_("[EOL]"); // end of list
break;
}
case Request::KillCall:
{
auto callId = task->_callId;
auto callId2 = Utils::toString(callId);
MSG_("asking daemon to kill : " + callId2);
DRing::hangUp(callId2);
break;
}
case Request::switchDebug:
{
debugModeOn_ = !debugModeOn_;
break;
}
default:
break;
}
......@@ -859,6 +886,42 @@ RingD::dequeueTasks()
}
}
void RingClientUWP::RingD::getCallsList()
{
auto task = ref new RingD::Task(Request::GetCallsList);
tasksList_.push(task);
}
void RingClientUWP::RingD::killCall(String ^ callId)
{
if (callId == "-all") {
auto callsList = DRing::getCallList();
for (auto call : callsList) {
auto task = ref new RingD::Task(Request::KillCall);
task->_callId = Utils::toPlatformString(call);
tasksList_.push(task);
}
return;
}
auto task = ref new RingD::Task(Request::KillCall);
task->_callId = callId;
tasksList_.push(task);
}
void RingClientUWP::RingD::switchDebug()
{
auto task = ref new RingD::Task(Request::switchDebug);
tasksList_.push(task);
}
RingClientUWP::CallStatus RingClientUWP::RingD::translateCallStatus(String^ state)
{
if (state == "INCOMING")
......
......@@ -99,6 +99,9 @@ internal:
void updateAccount(String^ accountId);
void deleteAccount(String^ accountId);
void registerThisDevice(String^ pin, String^ archivePassword);
void getCallsList();
void killCall(String^ callId);
void switchDebug();
/* TODO : move members */
String ^ currentCallId; // to save ongoing call id during visibility change
......@@ -130,7 +133,10 @@ private:
GetKnownDevices,
ExportOnRing,
UpdateAccount,
DeleteAccount
DeleteAccount,
GetCallsList,
KillCall,
switchDebug,
};
......@@ -175,5 +181,6 @@ private:
std::queue<Task^> tasksList_;
StartingStatus startingStatus_ = StartingStatus::NORMAL;
bool editModeOn_ = false;
bool debugModeOn_ = true;
};
}
\ No newline at end of file
......@@ -171,52 +171,87 @@ TrimFrom(Platform::String^ s)
}
Platform::String^
GetNewGUID()
TrimCmd(Platform::String^ s)
{
GUID result;
HRESULT hr = CoCreateGuid(&result);
const WCHAR* first = s->Begin();
const WCHAR* last = s->End();
if (SUCCEEDED(hr)) {
Guid guid(result);
return guid.ToString();
}
while (first != last && last[0] != '\ ' )
--last;
throw Exception::CreateException(hr);
}
//last--;
std::string
getStringFromFile(const std::string& filename)
{
std::ifstream file(filename);
return std::string((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()));
}
return ref new Platform::String(first, sizeof(last));
}
inline Map<String^,String^>^
convertMap(const std::map<std::string, std::string>& m)
{
auto temp = ref new Map<String^,String^>;
for (const auto& pair : m) {
temp->Insert(
Platform::String^
TrimParameter(Platform::String^ s)
{
const WCHAR* first = s->Begin();
const WCHAR* last = s->End();
while (first != last && *first != '[')
++first;
while (first != last && last[-1] != ']')
--last;
first++;
last--;
if (static_cast<unsigned int>(last - first) > 0)
return ref new Platform::String(first, static_cast<unsigned int>(last - first));
else
return "";
}
Platform::String^
GetNewGUID()
{
GUID result;
HRESULT hr = CoCreateGuid(&result);
if (SUCCEEDED(hr)) {
Guid guid(result);
return guid.ToString();
}
throw Exception::CreateException(hr);
}
std::string
getStringFromFile(const std::string& filename)
{
std::ifstream file(filename);
return std::string((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()));
}
inline Map<String^,String^>^
convertMap(const std::map<std::string, std::string>& m)
{
auto temp = ref new Map<String^,String^>;
for (const auto& pair : m) {
temp->Insert(
Utils::toPlatformString(pair.first),
Utils::toPlatformString(pair.second)
);
}
return temp;
}
);
}
return temp;
}
inline std::map<std::string, std::string>
convertMap(Map<String^,String^>^ m)
{
std::map<std::string, std::string> temp;
for (const auto& pair : m) {
temp.insert(
inline std::map<std::string, std::string>
convertMap(Map<String^,String^>^ m)
{
std::map<std::string, std::string> temp;
for (const auto& pair : m) {
temp.insert(
std::make_pair(
Utils::toString(pair->Key),
Utils::toString(pair->Value)));
}
return temp;
}
Utils::toString(pair->Key),
Utils::toString(pair->Value)));
}
return temp;
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment