Core.h 4.13 KB
Newer Older
1 2
/**************************************************************************/
/*                                                                        */
3
/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/.         */
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/*                                                                        */
/* NXCOMPSHAD, NX protocol compression and NX extensions to this software */
/* are copyright of NoMachine. Redistribution and use of the present      */
/* software is allowed according to terms specified in the file LICENSE   */
/* which comes in the source distribution.                                */
/*                                                                        */
/* Check http://www.nomachine.com/licensing.html for applicability.       */
/*                                                                        */
/* NX and NoMachine are trademarks of Medialogic S.p.A.                   */
/*                                                                        */
/* All rights reserved.                                                   */
/*                                                                        */
/**************************************************************************/

#ifndef CorePoller_H
#define CorePoller_H

#include <stdio.h>

#include "Logger.h"
#include "Regions.h"
#include "Input.h"

typedef enum{
  LINE_HAS_CHANGED,
  LINE_NOT_CHECKED,
  LINE_NOT_CHANGED
} LineStatus;

typedef enum{
  HIGHEST_PRIORITY = 0,
  PRIORITY = 30,
  NOT_PRIORITY = 90
} LinePriority;

class CorePoller
{
  public:

  CorePoller(Input*, Display*);

  virtual ~CorePoller();

  virtual int init();

  unsigned int width() const;

  unsigned int height() const;

  unsigned char depth() const;

  int isChanged(int (*)(void*), void *, int *);

  char *getFrameBuffer() const;

  void destroyFrameBuffer();

  void createFrameBuffer();

  Region lastUpdatedRegion();

  Region getLastUpdatedRegion();

  void handleInput();

  void handleEvent(Display *, XEvent *);

71 72
  void handleWebKeyEvent(KeySym keysym, Bool isKeyPress);

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  Display *getShadowDisplay();

  void setShadowDisplay(Display *shadowDisplay);

  protected:

  unsigned int bpp_;

  unsigned int bpl_;

  unsigned int width_;

  unsigned int height_;

  int depth_;

  char *buffer_;

  unsigned long redMask_;
  unsigned long greenMask_;
  unsigned long blueMask_;
  unsigned long colorMask_[3];

  char mirror_;

  char mirrorChanges_;

  virtual int updateShadowFrameBuffer(void) = 0;

  virtual char *getRect(XRectangle r) = 0;

  int imageByteOrder_;

  #ifdef __CYGWIN32__
  virtual char checkDesktop(void) = 0;
  #endif

  Display *shadowDisplay_;

  void update(char *src, XRectangle r);

  Region lastUpdatedRegion_;

  private:

  virtual void handleKeyboardEvent(Display *, XEvent *) = 0;

120 121
  virtual void handleWebKeyboardEvent(KeySym keysym, Bool isKeyPress) = 0;

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  virtual void handleMouseEvent(Display *, XEvent *) = 0;

  Input *input_;

  static const int maxSliceHeight_;
  static const int minSliceHeight_;

  LineStatus *lineStatus_;
  int *linePriority_;

  static const char interlace_[];

  int *lefts_;
  int *rights_;

  // FIXME: Make them friend.

  int differ(char *src, XRectangle r);
};

inline unsigned int CorePoller::width() const
{
  return width_;
}

inline unsigned int CorePoller::height() const
{
  return height_;
}

inline unsigned char CorePoller::depth() const
{
  return depth_;
}

inline char *CorePoller::getFrameBuffer() const
{
  return buffer_;
}

inline void CorePoller::destroyFrameBuffer()
{
  if (buffer_ != NULL)
  {
    delete[] buffer_;
    buffer_ = NULL;
  }
}

inline Region CorePoller::lastUpdatedRegion()
{
  Region region = lastUpdatedRegion_;

  lastUpdatedRegion_ = XCreateRegion();

  if (lastUpdatedRegion_ == NULL)
  {
    logError("CorePoller::lastUpdatedRegion", ESET(ENOMEM));

    lastUpdatedRegion_ = region;

    return NULL;
  }

  return region;
}

inline Region CorePoller::getLastUpdatedRegion()
{
  return lastUpdatedRegion_;
}

inline Display *CorePoller::getShadowDisplay()
{
  return shadowDisplay_ ;
}

inline void CorePoller::setShadowDisplay(Display *shadowDisplay)
{
  shadowDisplay_ = shadowDisplay;
}

#endif /* CorePoller_H */