172 lines
5.1 KiB
C
172 lines
5.1 KiB
C
/****************************************************************************
|
|
* graphics/vnc/vnc_updater.c
|
|
*
|
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
* used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <sched.h>
|
|
#include <pthread.h>
|
|
#include <assert.h>
|
|
|
|
#include "vnc_server.h"
|
|
|
|
/****************************************************************************
|
|
* Private Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: vnc_updater
|
|
*
|
|
* Description:
|
|
* This is the "updater" thread. It is the sender of all Server-to-Client
|
|
* messages
|
|
*
|
|
* Input Parameters:
|
|
* Standard pthread arguments.
|
|
*
|
|
* Returned Value:
|
|
* NULL is always returned.
|
|
*
|
|
****************************************************************************/
|
|
|
|
static FAR void *vnc_updater(FAR void *arg)
|
|
{
|
|
FAR struct vnc_session_s *session = (FAR struct vnc_session_s *)arg;
|
|
|
|
DEBUGASSERT(session != NULL);
|
|
|
|
while (session->state == VNCSERVER_RUNNING)
|
|
{
|
|
#warning Missing logic
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: vnc_start_updater
|
|
*
|
|
* Description:
|
|
* Start the updater thread
|
|
*
|
|
* Input Parameters:
|
|
* session - An instance of the session structure.
|
|
*
|
|
* Returned Value:
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
* any failure.
|
|
*
|
|
****************************************************************************/
|
|
|
|
int vnc_start_updater(FAR struct vnc_session_s *session)
|
|
{
|
|
pthread_attr_t attr;
|
|
struct sched_param param;
|
|
int status;
|
|
|
|
/* Create thread that is gonna send rectangles to the client */
|
|
|
|
session->state = VNCSERVER_RUNNING;
|
|
|
|
DEBUGVERIFY(pthread_attr_init(&attr));
|
|
DEBUGVERIFY(pthread_attr_setstacksize(&attr, CONFIG_VNCSERVER_UPDATER_STACKSIZE));
|
|
|
|
param.sched_priority = CONFIG_VNCSERVER_UPDATER_PRIO;
|
|
DEBUGVERIFY(pthread_attr_setschedparam(&attr, ¶m));
|
|
|
|
status = pthread_create(&session->updater, &attr, vnc_updater,
|
|
(pthread_addr_t)session);
|
|
if (status != 0)
|
|
{
|
|
return -status;
|
|
}
|
|
|
|
return OK;
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Name: vnc_stop_updater
|
|
*
|
|
* Description:
|
|
* Stop the updater thread
|
|
*
|
|
* Input Parameters:
|
|
* session - An instance of the session structure.
|
|
*
|
|
* Returned Value:
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
* any failure.
|
|
*
|
|
****************************************************************************/
|
|
|
|
int vnc_stop_updater(FAR struct vnc_session_s *session)
|
|
{
|
|
pthread_addr_t result;
|
|
int status;
|
|
|
|
/* Is the update thread running? */
|
|
|
|
if (session->state == VNCSERVER_RUNNING)
|
|
{
|
|
/* Yes.. ask it to please stop */
|
|
|
|
session->state = VNCSERVER_STOPPING;
|
|
|
|
/* Wait for the thread to comply with our request */
|
|
|
|
status = pthread_join(session->updater, &result);
|
|
if (status != 0)
|
|
{
|
|
return -status;
|
|
}
|
|
|
|
/* Return what the thread returned */
|
|
|
|
return (int)((intptr_t)result);
|
|
}
|
|
|
|
/* Not running? Just say we stopped the thread successfully. */
|
|
|
|
return OK;
|
|
}
|
|
|