display_utils.c

Go to the documentation of this file.
00001 /**
00002  * \file display_utils.c
00003  * \brief Display update wrapper functions
00004  */
00005 
00006 /*
00007  * This file is part of liberutils.
00008  *
00009  * liberutils is free software: you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation, either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * liberutils is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 /**
00024  * Copyright (C) 2009 iRex Technologies B.V.
00025  * All rights reserved.
00026  */
00027 
00028 //----------------------------------------------------------------------------
00029 // Include Files
00030 //----------------------------------------------------------------------------
00031 
00032 // system include files, between < >
00033 #include <glib.h>
00034 #include <stdio.h>
00035 #include <unistd.h>
00036 #include <arpa/inet.h>
00037 
00038 // ereader library include files, between < >
00039 #include "er_error.h"
00040 
00041 // local include files, between " "
00042 #include "log.h"
00043 #include "display_utils.h"
00044 
00045 
00046 //----------------------------------------------------------------------------
00047 // Type Declarations
00048 //----------------------------------------------------------------------------
00049 
00050 
00051 //----------------------------------------------------------------------------
00052 // Constants
00053 //----------------------------------------------------------------------------
00054 
00055 #define DMPORT                  50555
00056 #define DMSERVER                "127.0.0.1"
00057 
00058 
00059 //----------------------------------------------------------------------------
00060 // Static Variables
00061 //----------------------------------------------------------------------------
00062 
00063 static int                dm_socket = -1;
00064 static struct sockaddr_in dm_addr;
00065 
00066 
00067 //============================================================================
00068 // Local Function Definitions
00069 //============================================================================
00070 
00071 static void init_socket  (void);
00072 static void send_message (int take_control, int waveform);
00073 
00074 
00075 //============================================================================
00076 // Functions Implementation
00077 //============================================================================
00078 
00079 void display_init()
00080 {
00081     if (dm_socket == -1)
00082     {
00083         init_socket();
00084     }
00085 }
00086 
00087 
00088 void display_finialize()
00089 {
00090     if (dm_socket != -1)
00091     {
00092         close(dm_socket);
00093     }
00094 }
00095 
00096 void display_gain_control()
00097 {
00098     send_message(TRUE, DM_HINT_NONE);
00099 }
00100 
00101 
00102 void display_return_control()
00103 {
00104     send_message(FALSE, DM_HINT_NONE);
00105 }
00106 
00107 
00108 void display_update_return_control(int type)
00109 {
00110     send_message(FALSE, type);
00111 }
00112 
00113 
00114 void display_update_keep_control(int type)
00115 {
00116     send_message(TRUE, type);
00117 }
00118 
00119 
00120 void display_splash_lock()
00121 {
00122     send_message(TRUE, DM_HINT_LOCK);
00123 }
00124 
00125 
00126 void display_update_keep_splash_lock()
00127 {
00128     send_message(TRUE, DM_HINT_SPLASH);
00129 }
00130 
00131 
00132 void display_splash_unlock()
00133 {
00134     send_message(TRUE, DM_HINT_UNLOCK);
00135 }
00136 
00137 
00138 //============================================================================
00139 // Local Function Implementation
00140 //============================================================================
00141 
00142 static void init_socket()
00143 {
00144     // create and bind socket
00145     dm_socket = socket(PF_INET, SOCK_DGRAM, 0);
00146     dm_addr.sin_family = AF_INET;
00147     dm_addr.sin_port = htons(DMPORT);
00148     dm_addr.sin_addr.s_addr = inet_addr(DMSERVER);
00149     memset(dm_addr.sin_zero, '\0', sizeof(dm_addr.sin_zero));
00150 }
00151 
00152 
00153 static void send_message(int take_control, int waveform)
00154 {
00155     char msg[256];
00156     
00157     if (dm_socket == -1)
00158     {
00159         init_socket();
00160     }
00161     
00162     // send display update message
00163     snprintf(msg, sizeof(msg)-1, "!F,%d,%d,%d\n", getpid(), take_control > 0 ? 1 : 0, waveform);
00164     sendto(dm_socket, msg, strlen(msg), 0, (struct sockaddr*) &dm_addr, sizeof(dm_addr));
00165 
00166     LOGPRINTF("Sent: %s", msg);
00167 }
Generated by  doxygen 1.6.2-20100208