"Fossies" - the Fresh Open Source Software Archive

Member "tvnserver-2.0.4/tvncontrol-app/ControlProxy.cpp" (3 Aug 2011, 4475 Bytes) of archive /windows/misc/tvnserver-2.0.4-src.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ControlProxy.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2008, 2009, 2010 GlavSoft LLC.
    2 // All rights reserved.
    3 //
    4 //-------------------------------------------------------------------------
    5 // This file is part of the TightVNC software.  Please visit our Web site:
    6 //
    7 //                       http://www.tightvnc.com/
    8 //
    9 // This program is free software; you can redistribute it and/or modify
   10 // it under the terms of the GNU General Public License as published by
   11 // the Free Software Foundation; either version 2 of the License, or
   12 // (at your option) any later version.
   13 //
   14 // This program is distributed in the hope that it will be useful,
   15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17 // GNU General Public License for more details.
   18 //
   19 // You should have received a copy of the GNU General Public License along
   20 // with this program; if not, write to the Free Software Foundation, Inc.,
   21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   22 //-------------------------------------------------------------------------
   23 //
   24 
   25 #include "ControlProxy.h"
   26 #include "tvncontrol-app/ControlProto.h"
   27 #include "thread/AutoLock.h"
   28 
   29 #include <crtdbg.h>
   30 
   31 ControlProxy::ControlProxy(ControlGate *gate)
   32 : m_gate(gate), m_message(0),
   33   m_getPassFromConfigEnabled(false),
   34   m_forService(false)
   35 {
   36 }
   37 
   38 ControlProxy::~ControlProxy()
   39 {
   40   releaseMessage();
   41 }
   42 
   43 void ControlProxy::setPasswordProperties(const TCHAR *passwordFile,
   44                                          bool getPassFromConfigEnabled,
   45                                          bool forService)
   46 {
   47   m_passwordFile.setString(passwordFile);
   48   m_getPassFromConfigEnabled = getPassFromConfigEnabled;
   49   m_forService = forService;
   50 }
   51 
   52 TvnServerInfo ControlProxy::getServerInfo()
   53 {
   54   TvnServerInfo ret;
   55 
   56   AutoLock l(m_gate);
   57 
   58   createMessage(ControlProto::GET_SERVER_INFO_MSG_ID)->send();
   59 
   60   ret.m_acceptFlag = m_gate->readUInt8() == 1;
   61   ret.m_serviceFlag = m_gate->readUInt8() == 1;
   62 
   63   m_gate->readUTF8(&ret.m_statusText);
   64 
   65   return ret;
   66 }
   67 
   68 void ControlProxy::reloadServerConfig()
   69 {
   70   AutoLock l(m_gate);
   71 
   72   createMessage(ControlProto::RELOAD_CONFIG_MSG_ID)->send();
   73 }
   74 
   75 void ControlProxy::disconnectAllClients()
   76 {
   77   AutoLock l(m_gate);
   78 
   79   createMessage(ControlProto::DISCONNECT_ALL_CLIENTS_MSG_ID)->send();
   80 }
   81 
   82 void ControlProxy::shutdownTightVnc()
   83 {
   84   AutoLock l(m_gate);
   85 
   86   createMessage(ControlProto::SHUTDOWN_SERVER_MSG_ID)->send();
   87 }
   88 
   89 void ControlProxy::getClientsList(list<RfbClientInfo *> *clients)
   90 {
   91   AutoLock l(m_gate);
   92 
   93   createMessage(ControlProto::GET_CLIENT_LIST_MSG_ID)->send();
   94 
   95   UINT32 count = m_gate->readUInt32();
   96 
   97   for (UINT32 i = 0; i < count; i++) {
   98     StringStorage peerAddr;
   99 
  100     UINT32 id = m_gate->readUInt32();
  101 
  102     m_gate->readUTF8(&peerAddr);
  103 
  104     RfbClientInfo *clientInfo = new RfbClientInfo(id, peerAddr.getString());
  105 
  106     clients->push_back(clientInfo);
  107   }
  108 }
  109 
  110 void ControlProxy::makeOutgoingConnection(const TCHAR *connectString, bool viewOnly)
  111 {
  112   AutoLock l(m_gate);
  113 
  114   ControlMessage *msg = createMessage(ControlProto::ADD_CLIENT_MSG_ID);
  115 
  116   msg->writeUTF8(connectString);
  117   msg->writeUInt8(viewOnly);
  118 
  119   msg->send();
  120 }
  121 
  122 void ControlProxy::setServerConfig(ServerConfig *config)
  123 {
  124   AutoLock l(m_gate);
  125 
  126   ControlMessage *msg = createMessage(ControlProto::SET_CONFIG_MSG_ID);
  127 
  128   config->serialize(msg);
  129 
  130   msg->send();
  131 }
  132 
  133 void ControlProxy::getServerConfig(ServerConfig *config)
  134 {
  135   AutoLock l(m_gate);
  136 
  137   createMessage(ControlProto::GET_CONFIG_MSG_ID)->send();
  138 
  139   config->deserialize(m_gate);
  140 }
  141 
  142 bool ControlProxy::getShowTrayIconFlag()
  143 {
  144   AutoLock l(m_gate);
  145 
  146   createMessage(ControlProto::GET_SHOW_TRAY_ICON_FLAG)->send();
  147 
  148   return m_gate->readUInt8() == 1;
  149 }
  150 
  151 void ControlProxy::updateTvnControlProcessId(DWORD processId)
  152 {
  153   AutoLock l(m_gate);
  154 
  155   ControlMessage *msg = createMessage(ControlProto::UPDATE_TVNCONTROL_PROCESS_ID_MSG_ID);
  156 
  157   msg->writeUInt32(processId);
  158 
  159   msg->send();
  160 }
  161 
  162 ControlMessage *ControlProxy::createMessage(DWORD messageId)
  163 {
  164   releaseMessage();
  165 
  166   m_message = new ControlMessage(messageId, m_gate, m_passwordFile.getString(),
  167                                  m_getPassFromConfigEnabled, m_forService);
  168 
  169   return m_message;
  170 }
  171 
  172 void ControlProxy::releaseMessage()
  173 {
  174   if (m_message != 0) {
  175     delete m_message;
  176 
  177     m_message = 0;
  178   }
  179 }