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

Last change on this file since 242 was 242, checked in by Eugene Romanenko, 14 years ago

additional pipe commands

File size: 5.8 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";
52static const char *cmRotate     = "$rotate";
53static const char *cmZoomIn     = "$zoomin";
54static const char *cmZoomOut    = "$zoomout";
55static const char *cmZoomOrig   = "$zoomoriginal";
56
57
58static void pipeMonitor( void *p )
59{
60    HWND hWndFrame = (HWND)p;
61
62    HAB thab = WinInitialize( 0 );
63    HMQ hmq = WinCreateMsgQueue( thab, 0 );
64
65    char buf[ 100 ]  = "";
66    HPIPE PipeHandle = NULLHANDLE;
67    ULONG Readed     = 0;
68
69    if ( DosCreateNPipe( pipeName, &PipeHandle,
70                         NP_ACCESS_INBOUND | NP_NOINHERIT,
71                         NP_WAIT | NP_TYPE_MESSAGE | NP_READMODE_MESSAGE | 0x01,
72                         0, sizeof( buf ), 0 ) == 0 )
73    {
74        while ( true )
75        {
76            Readed = 0;
77            if ( DosConnectNPipe( PipeHandle ) != 0 ) {
78                break;
79            }
80            if ( DosRead( PipeHandle, buf, sizeof( buf ) - 1, &Readed ) == 0 )
81            {
82                if ( Readed != 0 )
83                {
84                    buf[ Readed ] = '\0';
85
86                    if ( strnicmp( buf, cmPrev, strlen( cmPrev ) ) == 0 )
87                    {
88                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_PREVPAGE ),
89                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
90                    }
91                    else if ( strnicmp( buf, cmNext, strlen( cmNext ) ) == 0 )
92                    {
93                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_NEXTPAGE ),
94                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
95                    }
96                    else if ( strnicmp( buf, cmMinimize, strlen( cmMinimize ) ) == 0 )
97                    {
98                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_MINIMIZE ),
99                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
100                    }
101                    else if ( strnicmp( buf, cmFullScreen, strlen( cmFullScreen ) ) == 0 )
102                    {
103                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_TOFULLSCREEN ),
104                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
105                    }
106                    else if ( strnicmp( buf, cmRotate, strlen( cmRotate ) ) == 0 )
107                    {
108                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ROTATE90CW ),
109                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
110                    }
111                    else if ( strnicmp( buf, cmZoomIn, strlen( cmZoomIn ) ) == 0 )
112                    {
113                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ZOOM_IN ),
114                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
115                    }
116                    else if ( strnicmp( buf, cmZoomOut, strlen( cmZoomOut ) ) == 0 )
117                    {
118                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ZOOM_OUT ),
119                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
120                    }
121                    else if ( strnicmp( buf, cmZoomOrig, strlen( cmZoomOrig ) ) == 0 )
122                    {
123                        WinPostMsg( hWndFrame, WM_COMMAND, MPFROMSHORT( CM_ACTSIZE ),
124                                    MPFROM2SHORT( CMDSRC_OTHER, TRUE ) );
125                    }
126                }
127            }
128            DosDisConnectNPipe( PipeHandle );
129        }
130
131        DosClose( PipeHandle );
132    }
133
134    WinDestroyMsgQueue( hmq );
135    WinTerminate( thab );
136}
137
138
139static int pmTid = -1;
140
141void initPipeMon( HWND hWndFrame )
142{
143    if ( pmTid == -1 ) {
144        pmTid = _beginthread( pipeMonitor, NULL, 32768, (void *)hWndFrame );
145    }
146}
147
148void unInitPipeMon()
149{
150    if ( pmTid != -1 ) {
151        TID tid = pmTid;
152        DosKillThread( tid );
153        DosWaitThread( &tid, DCWW_WAIT );
154    }
155}
156
Note: See TracBrowser for help on using the repository browser.