Results 1 to 6 of 6

Thread: A question on the issue12

  1. #1
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181

    A question on the issue12

    Hi,Matthew,
    In your article "Integrate ICE with GUI" in Issue 12, you mentioned the topic "Error checking". There,an exception from the working thread is propagated to GUI to show an error message. My question is why not, say, in Windows , using SendMessage() in the Catch as your first choice? I am now in a project with the same question and want to now your consideration on it.


    Thanks in advance.
    OrNot
    ------------------------------------------
    ornot2008@yahoo.com
    --------------------------------------------

  2. #2
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    The reason I didn't go for such a solution initially is it is more complex, requiring understanding of message queues, threading, and some more advanced memory management with C++. If you look at issue 15 I explore exactly such a solution, and describe implementations of such an approach with Qt, MFC and Java Swing. For most real world applications, I would use an approach which tells the user that an error has occurred immediately.

    BTW, if you are designing applications based on these articles you should be aware that starting with Ice 3.3 AMI calls will never block the calling thread. You can read about that in http://www.zeroc.com/newsletter/issue28.pdf.

  3. #3
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181
    Many thanks , Matthew. I read the Issue28. To transfer one Smart pointer from working thread to the GUI thread may be the best choice for me. But
    I still can not figure out how to implement this in win32 by SendMessage(or PostMessage). I don't know how to handle the smart pointer in the sender and receiver. I check the demo/mfc code but not found the sample code.
    I tried to find the similar approach from internet ,say, for boost's shared_ptr, but no explicit result. Could you pls give me some kind of indication?


    Thanks again.
    OrNot
    ------------------------------------------
    ornot2008@yahoo.com
    --------------------------------------------

  4. #4
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    If you look at MFC/server/LogI.cpp you'll find:

    Code:
    void
    LogI::post(const string& data)
    {
        assert(_hwnd != 0);
        char* text = new char[data.size()+1];
        strcpy(text, data.c_str());
        ::PostMessage(_hwnd, WM_USER, (WPARAM)FALSE, (LPARAM)text);
    }
    When this message is received the text is added to the text control, and then the memory freed.

    Code:
    LRESULT
    CHelloServerDlg::OnLog(WPARAM wParam, LPARAM lParam)
    {
        char* text = (char*)lParam;
    
        _edit->SetSel(-1, -1);
        _edit->ReplaceSel(CString(text));
    
        delete[] text;
    
        return 0;
    }
    You can use a similar approach in your application. In this case, a reference counted type is not necessary since the data is received by only a single recipient. If you have multiple recipients, or possibly no recipient then you'd need to take a different approach.

  5. #5
    OrNot is offline Registered User
    Name: Bin.Li
    Organization: GE Healthcare
    Project: Enterprise solution
    Join Date
    Jun 2005
    Location
    Shanghai
    Posts
    181
    Hi, Matthew,
    Yes, You are right. What I am concerning now is the situation as you mentioned:multiple recipients, or possibly no recipient .
    In Issue15, you demonstrated one example with ExceptionHolder in Qt.
    Is it similar to do this in MFC with sendmessage? In other words, the usage of emit error in Qt is similar to sendmessage in MFC? Sorry for my lack of Qt experience. I know in MFC sendmessage needs one pointer to the data ,but can't make sure how to handle one smart pointer (with reference count )here.
    I am sorry this question may beyond the scope of ICE , but any response will be appreciated.


    Regards
    OrNot
    ------------------------------------------
    ornot2008@yahoo.com
    --------------------------------------------

  6. #6
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    I don't really know enough about the structure of your application to give sensible advise, however, one approach that comes to mind is to put the unit of work in some shared, or global object and use PostMessage to trigger the recipient(s) to consume the work. In this way you are not passing data at all through the PostMessage parameters, but are merely using it as a way to signal the recipient that data is available.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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