source: trunk/Lucide/SOURCE/gui/pipemon.cpp @ 152

Last change on this file since 152 was 152, checked in by Eugene Romanenko, 15 years ago

pipe commands

File size: 4.4 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2 * Version: CDDL 1.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the COMMON DEVELOPMENT AND
5 * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
6 * this file except in compliance with the License. You may obtain a copy of
7 * the License at http://www.sun.com/cddl/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Initial Developer of the Original Code is
15 * Eugene Romanenko, netlabs.org.
16 * Portions created by the Initial Developer are Copyright (C) 2006
17 * the Initial Developer. All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * Alternatively, the contents of this file may be used under the terms of
22 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
23 * in which case the provisions of the LGPL are applicable instead of those
24 * above. If you wish to allow use of your version of this file only under the
25 * terms of the LGPL, and not to allow others to use your version of this file
26 * under the terms of the CDDL, indicate your decision by deleting the
27 * provisions above and replace them with the notice and other provisions
28 * required by the LGPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under the terms of any one of the CDDL
30 * or the LGPL.
31 *
32 * ***** END LICENSE BLOCK ***** */
33
34
35#define INCL_DOS
36#define INCL_WIN
37#include <os2.h>
38
39#include <string.h>
40#include <process.h>
41
42#include "Lucide_res.h"
43
44
45static const char *pipeName    = "\\PIPE\\LUCIDE";
46
47// Commands
48static const char *cmPrev       = "$prev";
49static const char *cmNext       = "$next";
50static const char *cmMinimize   = "$minimize";
51static const char *cmFullScreen = "$switchfullscreen";
52
53
54static void pipeMonitor( void *p )
55{
56    HWND hWndFrame = (HWND)p;
57
58    HAB thab = WinInitialize( 0 );
59    HMQ hmq = WinCreateMsgQueue( thab, 0 );
60
61    char buf[ 100 ]  = "";
62    HPIPE PipeHandle = NULLHANDLE;
63    ULONG Readed     = 0;
64
65    if ( DosCreateNPipe( pipeName, &PipeHandle,
66                         NP_ACCESS_INBOUND | NP_NOINHERIT,
67                         NP_WAIT | NP_TYPE_MESSAGE | NP_READMODE_MESSAGE | 0x01,
68                         0, sizeof( buf ), 0 ) == 0 )
69    {
70        while ( true )
71        {
72            Readed = 0;
73            if ( DosConnectNPipe( PipeHandle ) != 0 ) {
74                break;
75            }
76            if ( DosRead( PipeHandle, buf, sizeof( buf ) - 1, &Readed ) == 0 )
77            {
78                if ( Readed != 0 )
79                {
80                    buf[ Readed ] = '\0';
81
82                    if ( strnicmp( buf, cmPrev, strlen( cmPrev ) ) == 0 )
83                    {
84                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_PREVPAGE ),
85                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
86                    }
87                    else if ( strnicmp( buf, cmNext, strlen( cmNext ) ) == 0 )
88                    {
89                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_NEXTPAGE ),
90                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
91                    }
92                    else if ( strnicmp( buf, cmMinimize, strlen( cmMinimize ) ) == 0 )
93                    {
94                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_MINIMIZE ),
95                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
96                    }
97                    else if ( strnicmp( buf, cmFullScreen, strlen( cmFullScreen ) ) == 0 )
98                    {
99                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_TOFULLSCREEN ),
100                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
101                    }
102                }
103            }
104            DosDisConnectNPipe( PipeHandle );
105        }
106
107        DosClose( PipeHandle );
108    }
109
110    WinDestroyMsgQueue( hmq );
111    WinTerminate( thab );
112}
113
114
115static int pmTid = -1;
116
117void initPipeMon( HWND hWndFrame )
118{
119    if ( pmTid == -1 ) {
120        pmTid = _beginthread( pipeMonitor, NULL, 32768, (void *)hWndFrame );
121    }
122}
123
124void unInitPipeMon()
125{
126    if ( pmTid != -1 ) {
127        TID tid = pmTid;
128        DosKillThread( tid );
129        DosWaitThread( &tid, DCWW_WAIT );
130    }
131}
132
Note: See TracBrowser for help on using the repository browser.