1 | /** @file
|
---|
2 | *
|
---|
3 | * Shared Clipboard:
|
---|
4 | * Linux guest.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef __Additions_linux_clipboard_h
|
---|
20 | # define __Additions_linux_clipboard_h
|
---|
21 |
|
---|
22 | #include <VBox/log.h>
|
---|
23 | #include "thread.h" /* for VBoxGuestThread */
|
---|
24 |
|
---|
25 | extern void vboxClipboardDisconnect (void);
|
---|
26 | extern int vboxClipboardConnect (void);
|
---|
27 | extern int vboxClipboardMain (void);
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Display change request monitor thread function
|
---|
31 | */
|
---|
32 | class VBoxGuestClipboardThread : public VBoxGuestThreadFunction
|
---|
33 | {
|
---|
34 | private:
|
---|
35 | // Copying or assigning a thread object is not sensible
|
---|
36 | VBoxGuestClipboardThread(const VBoxGuestClipboardThread&);
|
---|
37 | VBoxGuestClipboardThread& operator=(const VBoxGuestClipboardThread&);
|
---|
38 |
|
---|
39 | // Private member variables
|
---|
40 | /** Have we been initialised yet? */
|
---|
41 | bool mInit;
|
---|
42 | /** The thread object running us. */
|
---|
43 | VBoxGuestThread *mThread;
|
---|
44 | public:
|
---|
45 | VBoxGuestClipboardThread() { mInit = false; }
|
---|
46 | /**
|
---|
47 | * Initialise the class and check that the guest supports dynamic resizing.
|
---|
48 | * @returns iprt status value
|
---|
49 | */
|
---|
50 | int init(void)
|
---|
51 | {
|
---|
52 | if (mInit)
|
---|
53 | return true;
|
---|
54 | return vboxClipboardConnect();
|
---|
55 | }
|
---|
56 | /**
|
---|
57 | * The actual thread function.
|
---|
58 | *
|
---|
59 | * @returns iprt status code as thread return value
|
---|
60 | * @param pParent the VBoxGuestThread running this thread function
|
---|
61 | */
|
---|
62 | virtual int threadFunction(VBoxGuestThread *pThread)
|
---|
63 | {
|
---|
64 | vboxClipboardMain();
|
---|
65 | return VINF_SUCCESS;
|
---|
66 | }
|
---|
67 | /**
|
---|
68 | * Send a signal to the thread function that it should exit
|
---|
69 | */
|
---|
70 | virtual void stop(void) { vboxClipboardDisconnect(); }
|
---|
71 | };
|
---|
72 |
|
---|
73 | class VBoxGuestClipboard
|
---|
74 | {
|
---|
75 | private:
|
---|
76 | /** No copying or assignment. */
|
---|
77 | VBoxGuestClipboard(const VBoxGuestClipboard &);
|
---|
78 | VBoxGuestClipboard& operator=(const VBoxGuestClipboard &);
|
---|
79 |
|
---|
80 | /** Our monitor thread function */
|
---|
81 | VBoxGuestClipboardThread mThreadFunction;
|
---|
82 | /** And the thread for the thread function */
|
---|
83 | VBoxGuestThread mThread;
|
---|
84 | /** Are we initialised? */
|
---|
85 | bool mInit;
|
---|
86 | public:
|
---|
87 | /**
|
---|
88 | * Initialise the class.
|
---|
89 | * @returns iprt status value
|
---|
90 | */
|
---|
91 | int init(void)
|
---|
92 | {
|
---|
93 | LogRelFlowFunc(("\n"));
|
---|
94 | int rc = mThreadFunction.init();
|
---|
95 | if (RT_SUCCESS(rc))
|
---|
96 | rc = mThread.start();
|
---|
97 | if (RT_SUCCESS(rc))
|
---|
98 | mInit = true;
|
---|
99 | LogRelFlowFunc(("returning %Rrc\n", rc));
|
---|
100 | return rc;
|
---|
101 | }
|
---|
102 | /**
|
---|
103 | * Uninitialise the class.
|
---|
104 | * @param cMillies how long to wait for the thread to stop
|
---|
105 | */
|
---|
106 | void uninit(RTMSINTERVAL cMillies = RT_INDEFINITE_WAIT)
|
---|
107 | {
|
---|
108 | LogRelFlowFunc(("\n"));
|
---|
109 | if (mInit)
|
---|
110 | mThread.stop(cMillies, NULL);
|
---|
111 | LogRelFlowFunc(("returning\n"));
|
---|
112 | }
|
---|
113 |
|
---|
114 | VBoxGuestClipboard() : mThread(&mThreadFunction, 0, RTTHREADTYPE_MSG_PUMP,
|
---|
115 | RTTHREADFLAGS_WAITABLE, "SHCLIP MAIN")
|
---|
116 | { mInit = false; }
|
---|
117 | ~VBoxGuestClipboard()
|
---|
118 | {
|
---|
119 | LogRelFlowFunc(("\n"));
|
---|
120 | if (mInit)
|
---|
121 | try {
|
---|
122 | uninit(2000);
|
---|
123 | } catch (...) { }
|
---|
124 | LogRelFlowFunc(("returning\n"));
|
---|
125 | }
|
---|
126 | };
|
---|
127 |
|
---|
128 | #endif /* __Additions_linux_clipboard_h not defined */
|
---|