# AppSharing interface

FrameBuffer: Interface to capture desktop or application bitmaps, find differences between bitmaps, generate blocks and compressing them.

Canvas: Interface to decompress blocks and display them.

## File information

File | common/interface/appsharing.h
Classes | IFrameBuffer UFrameBuffer CompressedBlock CompressedBlockNode ICanvas UCanvas

# Classes

## IFrameBuffer

    class IFrameBuffer {
    public:
        static IImageBuffer * CreateImageBuffer(class IIoMux * const iomux, class UFrameBuffer * const user, class IInstanceLog * const log, class MediaConfiguration * mediaConfiguration);
        virtual ~IFrameBuffer() {};
        virtual void Capture(unsigned int appId) = 0;  // MakeCapture, CreateDiffBlocks and CompressDiffBlocks
        virtual bool Mark(unsigned int appId, int coorX, int coorY, int dimX, int dimY) = 0;
        virtual void Clean(unsigned int appId) = 0;
        virtual void SubscribeApplications(void) = 0;
        virtual void UnsubscribeApplications(void) = 0;
        virtual void SetMousePosition(int coorX, int coorY) = 0;
        virtual void CloseFrameBuffer(void) = 0;
    };

### Overview

Base class for the frame buffer interface.

### Public functions

CreateFrameBuffer
  Creates an instance of the frame buffer.

  #### Parameters

  class IIoMux * const iomux | iomux is the IIoMux instance of the application.
  class UFrameBuffer * const user | UFrameBuffer instance that will receive the callbacks from the frame buffer.
  class IInstanceLog * const log | The IInstanceLog interface provides AppInstance related logs which are controlled by the log flag LOG_APPSHARING.

Capture
  Capture a bitmap of application.

  #### Parameters

  unsigned int appId | id of an application.

Mark
  Mark area in the bitmap for retransmission.

  #### Parameters

  unsigned int appId | id of an application.
  int coorX
  int coorY
  int dimX
  int dimY

Clean
  Clean saved information about a previous capture.

  #### Parameters

  unsigned int appId | id of an application.

SubscribeApplications
  Request the frame to provide a list of available applications and future updates.
UnsubscribeApplications
  Stop receiving updates of the applications.
RequestNewPicture
  Send a whole new picture of an application.

  #### Parameters

  unsigned int appId | id of an application.

CloseFrameBuffer
  Close the frame buffer.

## UFrameBuffer

    class UFrameBuffer {
    public:
        virtual void Add(unsigned int id, const char * name, const char * description, const char * icon,  const char * thumbnail, void * handle) {};
        virtual void Update(unsigned int id, const char * name, const char * description, const char * icon,  const char * thumbnail) {};
        virtual void Remove(unsigned int id) {};
        virtual void Event(void * buf, size_t len) {};
        virtual void HasData(unsigned int id) {};
        virtual void CloseComplete() {};
    };

### Overview

A class that receives updates from the frame buffer interface.

### Public functions

Add
  Provide information about an application.

  #### Parameters

  unsigned int appId | id of an application.
  const char * name | Name of the application.
  const char * description | Description of the application.
  const char * icon | Icon for the application.
  const char * thumbnail | Thumbnail of the application.
  void * handle | Platform dependent handle for the application.

Update
  Update information about an application.

  #### Parameters

  unsigned int appId | id of an application.
  const char * name | Name of the application.
  const char * description | Description of the application.
  const char * icon | Icon for the application.
  const char * thumbnail | Thumbnail of the application.

Remove
  Remove application.

  #### Parameters

  unsigned int appId | id of an application.

HasData
  Frame Buffer has data to send for an application.

  #### Parameters

  unsigned int appId | id of an application.

CloseComplete
  Frame Buffer was closed.

## CompressBlock

    class CompressedBlock {
    public:
        CompressedBlock() {
            this->buf = NULL;
            this->len = 0;
            this->first = false;
            this->last = false;
        };
        ~CompressedBlock() { if(this->buf) free(this->buf); };
        int coorX;
        int coorY;
        int dimX;
        int dimY;
        int picW;
        int picH;
        word seq;
        enum CompressionType compressionType;
        enum BlockType blockType;
        int numEqBlocks;
        unsigned char *buf;
        int len;
        int msg;
        bool first;
        bool last;
    };

### Overview

Provides all the information about a compress block.

## CompressedBlockNode

    class CompressedBlockNode {
    public:
        int userId;
        int appId;
        bool retransmissions;
    public:
        CompressedBlockNode(class CompressedBlock *pCompBlock, int userId, int appId, bool retransmissions) {
            this->pCompBlock = pCompBlock;
            this->retransmissions = retransmissions;
            this->appId = appId;
            this->userId = userId;
        };
        ~CompressedBlockNode() {
            if(pCompBlock) delete pCompBlock;
        }
        int GetUserId(void) { return userId; };
        int GetAppId(void) { return appId; };
        bool GetRetransmissions(void) { return retransmissions; };
        class CompressedBlock *pCompBlock;
    };

### Overview

Compress block for a user and application id.

## ICanvas

    class ICanvas {
    public:
        static ICanvas * CreateCanvas(class IIoMux * const iomux, class UCanvas * const user, class IInstanceLog * const log);
        virtual ~ICanvas() {};
        virtual void PutBlock(unsigned int userId, unsigned int appId, class CompressedBlock * block) = 0;
        virtual void DrawMouse(unsigned int userId, unsigned int appId, enum MouseType mouse, int coorX, int coorY) = 0;
        virtual void Add(unsigned int userId, char * userName, unsigned int appId, char * appName, char * appDesc) = 0;
        virtual void Update(unsigned int userId, char * userName, unsigned int appId, char * appName, char * appDesc) = 0;
        virtual void Remove(unsigned int userId, unsigned int appId) = 0;
        virtual void CloseCanvas(void) = 0;
    };

### Overview

Base class for the canvas interface.

### Public functions

CreateCanvas
  Creates an instance of the canvas interface.

  #### Parameters

  class IIoMux * const iomux | iomux is the IIoMux instance of the application.
  class UCanvas * const user | UCanvas instance that will receive the callbacks from the canvas.
  class IInstanceLog * const log | The IInstanceLog interface provides AppInstance related logs which are controlled by the log flag LOG_APPSHARING.

PuBlock
  Pass a compress block to the canvas interface.

  #### Parameters

  unsigned int userId | Blocks belongs to user id.
  unsigned int appId | Blocks belongs to application id.
  class CompressedBlock * block | Compress block.

DrawMouse
  Draw mouse type at the specific position.

  #### Parameters

  unsigned int userId | Blocks belongs to user id.
  unsigned int appId | Blocks belongs to application id.
  enum MouseType mouse | Mouse to display.
  int coorX
  int coorY

Add
  Compress Blocks for a new application received.

  #### Parameters

  unsigned int userId | Blocks belongs to user id.
  char * userName | Name of the user.
  unsigned int appId | Blocks belongs to application id.
  char * appName | Name of the application.
  char * appDesc | Description of the application.

Update
  New information for an application received.

  #### Parameters

  unsigned int userId | Blocks belongs to user id.
  char * userName | Name of the user.
  unsigned int appId | Blocks belongs to application id.
  char * appName | Name of the application.
  char * appDesc | Description of the application.

Remove
  Application was Removed.

  #### Parameters

  unsigned int userId | Blocks belongs to user id.
  unsigned int appId | Blocks belongs to application id.

CloseCanvas
  Close canvas interface

## UCanvas

    class UCanvas {
    public:
        virtual bool IsDesktopShared() = 0;
        virtual bool IsSharing(void) = 0;
        virtual bool GetApplicationPosition(unsigned int appId, int * coorX, int * coorY) = 0;
        virtual void SetWindowFront(unsigned int appId, int coorX, int coorY) = 0;
        virtual void Event(void * buf, size_t len) = 0;
        virtual void Send(void * buf, size_t len) = 0;
        virtual void SendTo(void * buf, size_t len, unsigned short senderId) = 0;
        virtual void Resend(unsigned short seq, unsigned short senderId) = 0;
        virtual void CloseComplete(void) = 0;
    };

### Overview

A class that receives updates from the canvas interface.

### Public functions

CloseComplete
  Canvas interface was closed