~marcustomlinson/unity-scopes-api/debug_dbus_messages

« back to all changes in this revision

Viewing changes to src/scopes/internal/RegistryObject.cpp

  • Committer: Marcus Tomlinson
  • Date: 2014-08-26 04:00:56 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20140826040056-rrarp4ijiaqnduzn
Addressed review comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <unity/scopes/internal/MWRegistry.h>
22
22
#include <unity/scopes/internal/RuntimeImpl.h>
 
23
#include <unity/scopes/internal/Utils.h>
23
24
#include <unity/scopes/ScopeExceptions.h>
24
25
#include <unity/UnityExceptions.h>
25
26
#include <unity/util/ResourcePtr.h>
35
36
 
36
37
using namespace std;
37
38
 
 
39
static const char* c_debug_dbus_started_cmd = "dbus-send --type=method_call --dest=com.ubuntu.SDKAppLaunch /ScopeRegistryCallback com.ubuntu.SDKAppLaunch.ScopeLoaded";
 
40
static const char* c_debug_dbus_stopped_cmd = "dbus-send --type=method_call --dest=com.ubuntu.SDKAppLaunch /ScopeRegistryCallback com.ubuntu.SDKAppLaunch.ScopeStopped";
 
41
 
38
42
namespace unity
39
43
{
40
44
 
524
528
    }
525
529
    else if (new_state == Running)
526
530
    {
527
 
        publish_state_change(true);
 
531
        publish_state_change(Running);
528
532
 
529
533
        if (state_ != Starting)
530
534
        {
536
540
    }
537
541
    else if (new_state == Stopped)
538
542
    {
539
 
        publish_state_change(false);
 
543
        publish_state_change(Stopped);
540
544
 
541
545
        if (state_ != Stopping)
542
546
        {
546
550
    }
547
551
    else if (new_state == Stopping && manually_started_)
548
552
    {
549
 
        publish_state_change(false);
 
553
        publish_state_change(Stopped);
550
554
 
551
555
        cout << "RegistryObject::ScopeProcess: Manually started process for scope: \""
552
556
             << exec_data_.scope_id << "\" exited" << endl;
652
656
    return command_args;
653
657
}
654
658
 
655
 
void RegistryObject::ScopeProcess::publish_state_change(bool scope_started)
 
659
void RegistryObject::ScopeProcess::publish_state_change(ProcessState scope_state)
656
660
{
657
 
    if (scope_started)
 
661
    if (scope_state == Running)
658
662
    {
659
663
        if (reg_publisher_)
660
664
        {
664
668
        if (exec_data_.debug_mode)
665
669
        {
666
670
            // If we're in debug mode, callback to the SDK via dbus (used to monitor scope lifecycle)
667
 
            std::string started_message = "dbus-send --type=method_call --dest=com.ubuntu.SDKAppLaunch "
668
 
                                          "/ScopeRegistryCallback com.ubuntu.SDKAppLaunch.ScopeLoaded "
669
 
                                          "string:" + exec_data_.scope_id + " "
670
 
                                          "uint64:" + std::to_string(process_.pid());
671
 
            if (std::system(started_message.c_str()) != 0)
 
671
            std::string started_message = c_debug_dbus_started_cmd;
 
672
            started_message += " string:" + exec_data_.scope_id + " uint64:" + std::to_string(process_.pid());
 
673
            if (safe_system_call(started_message) != 0)
672
674
            {
673
 
                std::cerr << "RegistryObject::ScopeProcess::publish_state_change(): Failed to execute SDK DBus callback" << endl;
 
675
                std::cerr << "RegistryObject::ScopeProcess::publish_state_change(): "
 
676
                             "Failed to execute SDK DBus ScopeLoaded callback "
 
677
                             "(Scope ID: " << exec_data_.scope_id << ")" << endl;
674
678
            }
675
679
        }
676
680
    }
677
 
    else if (scope_started == false)
 
681
    else if (scope_state == Stopped)
678
682
    {
679
683
        if (reg_publisher_)
680
684
        {
684
688
        if (exec_data_.debug_mode)
685
689
        {
686
690
            // If we're in debug mode, callback to the SDK via dbus (used to monitor scope lifecycle)
687
 
            std::string stopped_message = "dbus-send --type=method_call --dest=com.ubuntu.SDKAppLaunch "
688
 
                                          "/ScopeRegistryCallback com.ubuntu.SDKAppLaunch.ScopeStopped "
689
 
                                          "string:" + exec_data_.scope_id;
690
 
            if (std::system(stopped_message.c_str()) != 0)
 
691
            std::string stopped_message = c_debug_dbus_stopped_cmd;
 
692
            stopped_message += " string:" + exec_data_.scope_id;
 
693
            if (safe_system_call(stopped_message) != 0)
691
694
            {
692
 
                std::cerr << "RegistryObject::ScopeProcess::publish_state_change(): Failed to execute SDK DBus callback" << endl;
 
695
                std::cerr << "RegistryObject::ScopeProcess::publish_state_change(): "
 
696
                             "Failed to execute SDK DBus ScopeStopped callback "
 
697
                             "(Scope ID: " << exec_data_.scope_id << ")" << endl;
693
698
            }
694
699
        }
695
700
    }