vfs: check userland buffers before reading them.
[haiku.git] / src / libs / print / libprint / DialogWindow.cpp
blob8523a83ef738f1e35bc4a1985450674bd72680f8
1 /*
2 * DialogWindow.h
3 * Copyright 2004 Michael Pfeiffer. All Rights Reserved.
4 */
6 #include "DialogWindow.h"
8 #include <Messenger.h>
10 DialogWindow::DialogWindow(BRect frame,
11 const char *title,
12 window_type type,
13 uint32 flags,
14 uint32 workspace)
15 : BWindow(frame, title, type, flags, workspace)
16 , fPreviousResult(B_OK)
17 , fResult(NULL)
19 // nothing to do
22 DialogWindow::DialogWindow(BRect frame,
23 const char *title,
24 window_look look,
25 window_feel feel,
26 uint32 flags,
27 uint32 workspace)
28 : BWindow(frame, title, look, feel, flags, workspace)
29 , fPreviousResult(B_OK)
30 , fResult(NULL)
32 // nothing to do
35 void DialogWindow::MessageReceived(BMessage *msg)
37 if (msg->what == kGetThreadId) {
38 BMessage reply;
39 reply.AddInt32("thread_id", Thread());
40 msg->SendReply(&reply);
41 return;
43 BWindow::MessageReceived(msg);
46 status_t DialogWindow::Go()
48 BMessenger messenger(this, this);
49 // store result in local variable and
50 // initialize it with previous result
51 volatile status_t result = fPreviousResult;
52 // new results are stored on the stack
53 fResult = &result;
55 // show the window
56 Show();
57 // at this point we must not access member variables,
58 // because this object (the window) could already be deleted.
60 // get thread id of window thread
61 BMessage reply;
62 if (messenger.SendMessage(kGetThreadId, &reply) != B_OK) {
63 return B_ERROR;
65 thread_id windowThread;
66 if (reply.FindInt32("thread_id", &windowThread) != B_OK) {
67 return B_ERROR;
70 // wait for window thread to die
71 // The window thread will crash if the image holding the
72 // code used by the window thread is unloaded while the thread is
73 // still running!!!
74 status_t status = B_ERROR;
75 wait_for_thread(windowThread, &status);
77 return result;
80 void DialogWindow::SetResult(status_t result)
82 if (fResult != NULL) {
83 *fResult = result;
84 } else {
85 fPreviousResult = result;