×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    16

    Help - Design a solution

    Hello.
    Suppose that i have main.cpp- the initializations there (console etc..)
    and i have another file - class which implement an active object.
    so i want to call to Start function from the main file, hence i create an object of the class (in the main file) and call the the start function .(object->Start)
    now suppose that from the RunL i want to write to the console something, so i need to transfer the pointer of the console to the constructor of the class.

    Here comes the problem.
    I want something more generic, if in the future i would like to write to a file and not to a console ? so i don't want to pass the console pointer to the constructor.

    Is there a solution to this problem ?

    Thanks in advance.
    Alex.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Help - Design a solution

    You can push some interface+wrapper between the two. The simple approach is accepting a single descriptor and requiring the client to do the TDes::Format magic, but you can also do it on your side, TDes::FormatList can do that for you.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: Help - Design a solution

    How can I solve this problem by using M class?

    Thanks!

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Help - Design a solution

    You define an interface
    Code:
    class MTextOutput
    {
    public:
        virtual void MtoOutputText(const TDesC &aText)=0;
    };
    and store an MTextOutput * (or &) in the object.
    Provide a lightweight wrapper to your console object in the current code:
    Code:
    class CConsoleOutput : public CBase, public MTextOutput
    {
    public:
        CConsoleOutput(CConsoleBase &aConsole);
        void MtoOutputText(const TDesC &aText);
    private:
        CConsoleBase &iConsole;
    };
    implement it
    Code:
    CConsoleOutput::CConsoleOutput(CConsoleBase &aConsole):iConsole(aConsole)
    {}
    
    void CConsoleOutput::MtoOutputText(const TDesC &aText)
    {
        iConsole.Printf(aText);
    }
    instantiate it
    Code:
    CConsoleOutput *cco=new(ELeave)CConsoleOutput(*console);
    and pass to your object as MTextOutput.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: Help - Design a solution

    Thank you very much.

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Help - Design a solution

    You have slightly mis-interpreted it.
    CChargerActive should require and store an MTextOutput pointer or reference, and it should never know or care about where the given text goes, that is the point of having an interface.
    The CConsoleOutput object should be owned outside of CChargerActive, it can be a local variable in your MainL for example.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    16

    Re: Help - Design a solution

    OK, but the problem is that I want to print from the CChargeActive class!
    so CChargeActive has a member MTextOutput& iTextOutput.
    and in MainL i create an CConsoleOutput object (initialize with the console).
    by calling iTextOutput.MToOutputText(text) from CChargeActive -how it knows that i mean to the console??

    Thanks.

  8. #8
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Help - Design a solution

    I meant an usual console base code, something like this
    Code:
    void MainL()
    {
        CConsoleBase *console=Console::NewL(KNullDesC,TSize(KConsFullScreen,KConsFullScreen));
        CleanupStack::PushL(console);
    
        CConsoleOutput *wrapper=new(ELeave)CConsoleOutput(*console);
        CleanupStack::PushL(wrapper);
    
        CChargerActive *active=CChargerActive::NewL(*wrapper);
        CleanupStack::PushL(active);
    
        CActiveScheduler::Start();
    
        CleanupStack::PopAndDestroy(3); // active,wrapper,console
    }
    and CChargerActive gets and uses an MTextOutput

Similar Threads

  1. How to link 2 different UI Design?
    By Rachel Lee in forum Symbian
    Replies: 1
    Last Post: 2010-03-04, 07:23
  2. MMS Picture Store Solution
    By compilot in forum General Messaging
    Replies: 1
    Last Post: 2002-07-11, 16:40

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×