0

Boost Statechart Library を使用して IVR 内の呼び出しのフローを処理できるステート マシンを実装しようとしていますが、C++ に非常に慣れていないため、いくつかの基本的な操作が必要です。

私のコール フローが次のようになっているとしましょう: (最初の 2 つの状態 USR_checkSubscription と USR_checkBalance に注目) 通話の流れ

私の質問は単純ですが、それを機能させる方法を見つけることができます! 初期状態がUSR_checkSubscriptionになることはわかっていますが、その状態に入ると、そこで作成したものに応じて他の状態に移動するにはどうすればよいでしょうか。 1.

これは私の SM_callModel.cpp です

#include "SM_callModel.h"
using namespace std;
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
// States definition
struct USR_checkSubscription;
struct USR_checkBalance;
struct MNU_welcomeSubscribed;
struct MNU_mainMenu;
struct MNU_selectLeague;
struct MNU_menu1Content;
struct USR_selectSubscription;
struct USR_waitingForNumber;
struct USR_wrongNumber;
struct USR_confirmSubscription;
struct USR_chargeUser;
struct USR_inssuficientBalance;
struct USR_selectTopUp;
struct USR_endCall;
// Events definition
struct EvSubscribed : sc::event< EvSubscribed> {};
struct EvNotSubscribed : sc::event< EvNotSubscribed > {};
struct EvPressNumberNotSubscribed : sc::event< EvPressNumberNotSubscribed > {};
struct EvBalance : sc::event< EvBalance > {};
struct EvNoBalance : sc::event< EvNoBalance > {};
struct EvPressNumber : sc::event< EvPressNumber > {};
struct EvGoToConfirmSubscription : sc::event< EvGoToConfirmSubscription > {};
struct EvGoToChargeUser : sc::event< EvGoToChargeUser > {};
struct EvNotCharged : sc::event< EvNotCharged > {};
struct EvGoToMainMenu : sc::event< EvGoToMainMenu > {};
struct EvMenu1 : sc::event< EvMenu1 > {};
struct EvGoToMenu1Content : sc::event< EvGoToMenu1Content > {};
struct EvWrongNumber : sc::event< EvWrongNumber > {};
struct EvNoTime : sc::event< EvNoTime > {};
struct EvReturn : sc::event< EvReturn > {};
struct EvEndCall : sc::event< EvEndCall > {};
struct VoiceSM : sc::state_machine< VoiceSM, USR_checkSubscription > {};// The initialization state
VoiceSM VSM;
/* Check user subscription status */
struct USR_checkSubscription : sc::simple_state< USR_checkSubscription, VoiceSM>
{
    USR_checkSubscription() {
        // Check if user is subscribed via WebService (lets say it returns as subscribed = 1)
        int subscribed = 1;
        //HOW CAN I GO TO "EvSubscribed" OR "EvNotSubscribed" DEPENDING ON THE VARIABLE SUBSCRIBED???
        cout << "User is subscribed 1/0 n" << endl;
    }
    ~USR_checkSubscription() {}
    typedef mpl::list<
    sc::transition< EvSubscribed, USR_checkBalance >, // if is subscribed then go to USR_checkBalance
    sc::transition< EvNotSubscribed, USR_selectSubscription > > reactions; // if is not subscribed go to USR_selectSubscription
};
/* Check user current balance */
struct USR_checkBalance : sc::simple_state< USR_checkBalance, VoiceSM>
{
    USR_checkBalance() {
        // Check balance with web service
        cout << "User has balance Y/N? n" << endl;
    }
    ~USR_checkBalance() {}
    typedef mpl::list<
    sc::transition< EvBalance, MNU_welcomeSubscribed >,
    sc::transition< EvNoBalance, USR_selectTopUp > > reactions;
};
/* User press 1 to get 15 minutes to his account */
struct USR_selectTopUp : sc::simple_state< USR_selectTopUp, VoiceSM>
{
    USR_selectTopUp() {
        // Check balance with web service
        cout << "User selected 15 minutes n" << endl;
    }
    ~USR_selectTopUp() {}
    typedef mpl::list<
    sc::transition< EvGoToChargeUser, USR_chargeUser >,
    sc::transition< EvNoTime, USR_waitingForNumber >,
    sc::transition< EvWrongNumber, USR_wrongNumber > > reactions;
};
/* Play welcome audio for subscribed users */
struct MNU_welcomeSubscribed : sc::simple_state< MNU_welcomeSubscribed, VoiceSM>
{
    MNU_welcomeSubscribed() {
        // Check balance with web service
        cout << "Welcome user xxxxxx n" << endl;
    }
    ~MNU_welcomeSubscribed() {}
    typedef sc::transition< EvGoToMainMenu, MNU_mainMenu > reactions;
};
/* Play audio when user didn't digit anything */
struct USR_waitingForNumber : sc::simple_state< USR_waitingForNumber, VoiceSM>
{
    USR_waitingForNumber() {
        // Check balance with web service
        cout << "User didn't press any digit, its being redirected n" << endl;
    }
    ~USR_waitingForNumber() {}
    typedef sc::transition< EvGoToMainMenu, MNU_mainMenu > reactions;
};
/* Play audio when user inputs a wrong number */
struct USR_wrongNumber : sc::simple_state< USR_wrongNumber, VoiceSM>
{
    USR_wrongNumber() {
        // Counter ++
        // Get previous activity and then go back???
        cout << "User pressed the wrong number, try again n" << endl;
    }
    ~USR_wrongNumber() {}
    typedef sc::transition< EvGoToMainMenu, MNU_mainMenu > reactions;
};
/* Check user current balance */
struct USR_selectSubscription : sc::simple_state< USR_selectSubscription, VoiceSM>
{
    USR_selectSubscription() {
        // Select 1 or 2 for type of subscription
        cout << "User selected 1 or 2 n" << endl;
    }
    ~USR_selectSubscription() {}
    typedef mpl::list<
    sc::transition< EvGoToConfirmSubscription, USR_confirmSubscription >,
    sc::transition< EvNoTime, USR_waitingForNumber >,
    sc::transition< EvWrongNumber, USR_wrongNumber > > reactions;
};
/* Confirm user subscription */
struct USR_confirmSubscription : sc::simple_state< USR_confirmSubscription, VoiceSM>
{
    USR_confirmSubscription() {
        // Select 1 or 2 for type of subscription
        cout << "Press 1 or 2 to select  n" << endl;
    }
    ~USR_confirmSubscription() {}
    typedef mpl::list<
    sc::transition< EvGoToChargeUser, USR_chargeUser >,
    sc::transition< EvNoTime, USR_waitingForNumber >,
    sc::transition< EvWrongNumber, USR_wrongNumber > > reactions;
};
/* Charge the user */
struct USR_chargeUser : sc::simple_state< USR_chargeUser, VoiceSM>
{
    USR_chargeUser() {
        // Connect to web service to charge user depending on type of subscription
        cout << "Press 1 or 2 to select  n" << endl;
    }
    ~USR_chargeUser() {}
    typedef mpl::list<
    sc::transition< EvGoToMainMenu, MNU_mainMenu >,
    sc::transition< EvNotCharged, USR_inssuficientBalance >,
    sc::transition< EvNoTime, USR_waitingForNumber >,
    sc::transition< EvWrongNumber, USR_wrongNumber > > reactions;
};
/* User has no balance, end the call */
struct USR_inssuficientBalance : sc::simple_state< USR_inssuficientBalance, VoiceSM>
{
    USR_inssuficientBalance() {
        // Play audio of inssuficient balance and end call
        cout << "User doesn't have enough balance, end call.  n" << endl;
    }
    ~USR_inssuficientBalance() {}
    typedef sc::transition< EvEndCall, USR_endCall > reactions;
};
/* Play audio with main menu and wait for user input */
struct MNU_mainMenu : sc::simple_state< MNU_mainMenu, VoiceSM>
{
    MNU_mainMenu() {
        cout << "Press 1 - 8 from the menu  n" << endl;
    }
    ~MNU_mainMenu() {}
    typedef mpl::list<
    sc::transition< EvMenu1, MNU_selectLeague >,
    sc::transition< EvNoTime, USR_waitingForNumber >,
    sc::transition< EvWrongNumber, USR_wrongNumber > > reactions;
};
/* Select League (Liga Americana/Nacional) wait for 1 or 2 digits */
struct MNU_selectLeague : sc::simple_state< MNU_selectLeague, VoiceSM>
{
    MNU_selectLeague() {
        cout << "Select a league  n" << endl;
    }
    ~MNU_selectLeague() {}
    typedef mpl::list<
    sc::transition< EvGoToMenu1Content, MNU_menu1Content >,
    sc::transition< EvNoTime, USR_waitingForNumber >,
    sc::transition< EvWrongNumber, USR_wrongNumber > > reactions;
};
/* Menu 1 Content */
struct MNU_menu1Content : sc::simple_state< MNU_menu1Content, VoiceSM>
{
    MNU_menu1Content() {
        cout << "Content for menu 1 n" << endl;
    }
    ~MNU_menu1Content() {}
    typedef sc::transition< EvGoToMenu1Content, MNU_menu1Content > reactions;
};
int main()
{
    VSM.initiate();
    return 0;
}
4

1 に答える 1

1

解決しました!(友人の助けを借りて)そのため、コンストラクターから simple_state の外部コンテキストにアクセスしようとしていました。

このアサートは、state<> のサブタイプではない状態のコンストラクターから外部コンテキストにアクセスしようとすると失敗します。これを修正するには、simple_state<> ではなく state<> から派生させます。

つまり、simple_state<> の代わりに state<> を実装する必要がありました。

これがどのようにする必要があるかのいくつかのコーディングです

#include <boost/statechart/state.hpp>

struct state_1 : sc::state< state_1, DU >
{
    int suscription = 1;

    state_1( my_context ctx ) : my_base( ctx )
    {
        if (suscription == 1){
            cout<<"Going to event yes \n"<<endl;
            post_event( EvYes() );

        } else {
            post_event( EvNo() );
        }

    }
    typedef mpl::list< // Reaction to Events
    sc::transition< EvYes, state_4 >,
    sc::transition< EvNo, state_2 > > reactions;
};
于 2015-05-28T16:44:45.350 に答える