|
From: <ste...@us...> - 2010-01-23 18:53:52
|
Revision: 524
http://g15daemon.svn.sourceforge.net/g15daemon/?rev=524&view=rev
Author: steelside
Date: 2010-01-23 18:53:46 +0000 (Sat, 23 Jan 2010)
Log Message:
-----------
The bug about needing a g15_send before g15_send_cmd should be fixed. This commit has alot of debugprints (kdevelop + gdb + this project = no go) which will be removed later. Also, the MR key will not light up by default no longer, and will only activate if told to.
Modified Paths:
--------------
trunk/g15daemon/g15daemon/g15_net.c
trunk/g15daemon/g15daemon/linked_lists.c
trunk/g15daemon/g15daemon/main.c
trunk/g15daemon/g15daemon/utility_funcs.c
Modified: trunk/g15daemon/g15daemon/g15_net.c
===================================================================
--- trunk/g15daemon/g15daemon/g15_net.c 2009-10-17 22:22:46 UTC (rev 523)
+++ trunk/g15daemon/g15daemon/g15_net.c 2010-01-23 18:53:46 UTC (rev 524)
@@ -16,9 +16,9 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
(c) 2006-2007 Mike Lampard, Philip Lawatsch, and others
-
+
$Revision$ - $Date$ $Author$
-
+
This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients.
Client screens can be cycled through by pressing the 'L1' key.
@@ -32,7 +32,9 @@
#include <arpa/inet.h>
#include <unistd.h>
#include <pthread.h>
+#include <fcntl.h>
+
#include <errno.h>
#include <libg15.h>
#include "g15daemon.h"
@@ -51,7 +53,7 @@
int msgret;
if(current_key_state){
/* send the keystate inband back to the client */
- if((msgret = send(sock,(void *)¤t_key_state,sizeof(current_key_state),0))<0)
+ if((msgret = send(sock,(void *)¤t_key_state,sizeof(current_key_state),0))<0)
daemon_log(LOG_WARNING,"Error in send: %s\n",strerror(errno));
current_key_state = 0;
}
@@ -60,11 +62,11 @@
static void process_client_cmds(lcdnode_t *lcdnode, int sock, unsigned int *msgbuf, unsigned int len)
{
int msgret;
- if(msgbuf[0] == CLIENT_CMD_GET_KEYSTATE)
+ if(msgbuf[0] == CLIENT_CMD_GET_KEYSTATE)
{ /* client wants keypresses */
if(lcdnode->list->current == lcdnode){
/* send the keystate inband back to the client */
- if((msgret = send(sock,(void *)¤t_key_state,sizeof(current_key_state),0))<0)
+ if((msgret = send(sock,(void *)¤t_key_state,sizeof(current_key_state),0))<0)
daemon_log(LOG_WARNING,"Error in send: %s\n",strerror(errno));
current_key_state = 0;
}
@@ -72,7 +74,7 @@
memset(msgbuf,0,4); /* client isn't currently being displayed.. tell them nothing */
msgret=send(sock,(void *)msgbuf,sizeof(current_key_state),0);
}
- } else if(msgbuf[0] == CLIENT_CMD_SWITCH_PRIORITIES)
+ } else if(msgbuf[0] == CLIENT_CMD_SWITCH_PRIORITIES)
{ /* client wants to switch priorities */
pthread_mutex_lock(&lcdlist_mutex);
if(lcdnode->list->current != lcdnode){
@@ -92,7 +94,7 @@
}
}
pthread_mutex_unlock(&lcdlist_mutex);
- } else if(msgbuf[0] == CLIENT_CMD_IS_FOREGROUND)
+ } else if(msgbuf[0] == CLIENT_CMD_IS_FOREGROUND)
{ /* client wants to know if it's currently viewable */
pthread_mutex_lock(&lcdlist_mutex);
if(lcdnode->list->current == lcdnode){
@@ -102,7 +104,7 @@
}
pthread_mutex_unlock(&lcdlist_mutex);
send(sock,msgbuf,1,0);
- } else if (msgbuf[0] == CLIENT_CMD_IS_USER_SELECTED)
+ } else if (msgbuf[0] == CLIENT_CMD_IS_USER_SELECTED)
{ /* client wants to know if it was set to foreground by the user */
pthread_mutex_lock(&lcdlist_mutex);
if(lcdnode->lcd->usr_foreground) /* user manually selected this lcd */
@@ -111,29 +113,32 @@
msgbuf[0] = '0';
pthread_mutex_unlock(&lcdlist_mutex);
send(sock,msgbuf,1,0);
- } else if (msgbuf[0] & CLIENT_CMD_BACKLIGHT)
+ } else if (msgbuf[0] & CLIENT_CMD_BACKLIGHT)
{ /* client wants to change the backlight */
lcdnode->lcd->backlight_state = msgbuf[0]-0x80;
+ daemon_log(LOG_INFO,"CLIENT_CMD_BACKLIGHT. state_changed=1");
lcdnode->lcd->state_changed = 1;
- } else if (msgbuf[0] & CLIENT_CMD_CONTRAST)
+ } else if (msgbuf[0] & CLIENT_CMD_CONTRAST)
{ /* client wants to change the LCD contrast */
lcdnode->lcd->contrast_state = msgbuf[0]-0x40;
+ daemon_log(LOG_INFO,"CLIENT_CMD_CONTRAST. state_changed=1");
lcdnode->lcd->state_changed = 1;
- } else if (msgbuf[0] & CLIENT_CMD_MKEY_LIGHTS)
+ } else if (msgbuf[0] & CLIENT_CMD_MKEY_LIGHTS)
{ /* client wants to change the M-key backlights */
lcdnode->lcd->mkey_state = msgbuf[0]-0x20;
+ daemon_log(LOG_INFO,"CLIENT_CMD_MKEY_LIGHTS. state_changed=1");
lcdnode->lcd->state_changed = 1;
- } else if (msgbuf[0] & CLIENT_CMD_KEY_HANDLER)
+ } else if (msgbuf[0] & CLIENT_CMD_KEY_HANDLER)
{ /* client wants to take control of the G&M keys */
daemon_log(LOG_WARNING, "Client is taking over keystate");
-
- client_handles_keys=1;
+
+ client_handles_keys=1;
keyhandler = &lcdnode->lcd;
keyhandler->connection = sock;
-
+
daemon_log(LOG_WARNING, "Client has taken over keystate");
}
-
+
}
/* create and open a socket for listening */
@@ -142,7 +147,7 @@
int yes=1;
int tos = 0x18;
- struct sockaddr_in servaddr;
+ struct sockaddr_in servaddr;
if ((listening_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
daemon_log(LOG_WARNING, "Unable to create socket.\n");
@@ -151,7 +156,7 @@
setsockopt(listening_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
setsockopt(listening_socket, SOL_SOCKET, SO_PRIORITY, &tos, sizeof(tos));
-
+
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
inet_aton (LISTEN_ADDR, &servaddr.sin_addr);
@@ -177,7 +182,7 @@
int retval = 0;
int bytesleft = len;
struct pollfd pfd[1];
-
+
while(total < len && !leaving) {
memset(pfd,0,sizeof(pfd));
pfd[0].fd = sock;
@@ -185,8 +190,8 @@
if(poll(pfd,1,500)>0) {
if(pfd[0].revents & POLLOUT && !(pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL)) {
retval = send(sock, buf+total, bytesleft, 0);
- if (retval == -1) {
- break;
+ if (retval == -1) {
+ break;
}
bytesleft -= retval;
total += retval;
@@ -198,7 +203,7 @@
}
}
return retval==-1?-1:0;
-}
+}
int g15_recv(lcdnode_t *lcdnode, int sock, char *buf, unsigned int len)
@@ -206,37 +211,75 @@
int total = 0;
int retval = 0;
int msgret = 0;
- int bytesleft = len;
+ int bytesleft = len;
struct pollfd pfd[1];
unsigned int msgbuf[20];
+ int pollresult = 0;
+ int flags;
+ flags = fcntl(sock,F_GETFL,0);
+ fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+
while(total < len && !leaving) {
memset(pfd,0,sizeof(pfd));
+
pfd[0].fd = sock;
pfd[0].events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL;
- if(poll(pfd,1,500)>0){
- if(pfd[0].revents & POLLPRI && !(pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL)) { /* receive out-of-band request from client and deal with it */
+ daemon_log(LOG_INFO,"loop: g15_recv");
+ pollresult = poll(pfd,1,500);
+ if(pollresult > 0)
+ {
+ daemon_log(LOG_INFO, "Polling socket");
+ if(pfd[0].revents & POLLPRI && !(pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL))
+ { /* receive out-of-band request from client and deal with it */
+ daemon_log(LOG_INFO,"Reading OOB data");
memset(msgbuf,0,20);
- msgret = recv(sock, msgbuf, 10 , MSG_OOB);
- if (msgret < 1) {
+ msgret = recv(sock, msgbuf, 20 , MSG_OOB);
+ daemon_log(LOG_INFO,"Read OOB data");
+ if (msgret < 1)
+ {
+ daemon_log(LOG_INFO,"Breaking due to low returnvalue from recv()");
break;
}
- process_client_cmds(lcdnode, sock, msgbuf,len);
+ daemon_log(LOG_INFO,"Processing commands");
+ process_client_cmds(lcdnode, sock, msgbuf,len);
+ daemon_log(LOG_INFO,"Processed commands");
}
- else if(pfd[0].revents & POLLIN && !(pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL)) {
-
+ else if(pfd[0].revents & POLLIN && !(pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL || pfd[0].revents & POLLPRI))
+ {
+ daemon_log(LOG_INFO,"Reading normal data");
retval = recv(sock, buf+total, bytesleft, 0);
- if (retval < 1) {
- break;
+ daemon_log(LOG_INFO,"Reading normal data finished");
+ if (retval == 0)
+ {
+ break;
}
- total += retval;
- bytesleft -= retval;
- }
- if((pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL)){
- retval=-1;
- break;
- }
- }
+ else if (retval == -1)
+ continue;
+
+ total += retval;
+ bytesleft -= retval;
+ }
+ if((pfd[0].revents & POLLERR || pfd[0].revents & POLLHUP || pfd[0].revents & POLLNVAL))
+ {
+ daemon_log(LOG_ERR,"Socket error: %s", strerror(errno));
+ // Due to polling the above should never occur!
+ if (errno != EAGAIN)
+ {
+ retval=-1;
+ break;
+ }
+ }
+ daemon_log(LOG_INFO,"Total: %i. len: %i. Leaving: %i %i",total,len,leaving, (total < len));
+ }
+ else if (pollresult == 0)
+ {
+ daemon_log(LOG_INFO, "Polling timeout");
+ }
+ else
+ {
+ daemon_log(LOG_INFO,"Poll: %i", pollresult);
+ }
}
return total;
-}
+}
Modified: trunk/g15daemon/g15daemon/linked_lists.c
===================================================================
--- trunk/g15daemon/g15daemon/linked_lists.c 2009-10-17 22:22:46 UTC (rev 523)
+++ trunk/g15daemon/g15daemon/linked_lists.c 2010-01-23 18:53:46 UTC (rev 524)
@@ -14,11 +14,11 @@
You should have received a copy of the GNU General Public License
along with g15daemon; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
+
(c) 2006-2007 Mike Lampard, Philip Lawatsch, and others
$Revision$ - $Date$ $Author$
-
+
This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients.
Client screens can be cycled through by pressing the 'L1' key.
@@ -39,11 +39,11 @@
lcd->max_x = LCD_WIDTH;
lcd->max_y = LCD_HEIGHT;
lcd->backlight_state = G15_BRIGHTNESS_MEDIUM;
- lcd->mkey_state = G15_LED_MR;
+ lcd->mkey_state = 0;
lcd->contrast_state = G15_CONTRAST_MEDIUM;
lcd->state_changed = 1;
- lcd->usr_foreground = 0;
-
+ lcd->usr_foreground = 0;
+
return (lcd);
}
@@ -54,67 +54,67 @@
/* initialise a new displaylist, and add an initial node at the tail (used for the clock) */
lcdlist_t *lcdlist_init () {
-
+
lcdlist_t *displaylist = NULL;
-
+
pthread_mutex_init(&lcdlist_mutex, NULL);
pthread_mutex_lock(&lcdlist_mutex);
-
+
displaylist = g15_xmalloc(sizeof(lcdlist_t));
-
+
displaylist->head = g15_xmalloc(sizeof(lcdnode_t));
-
+
displaylist->tail = displaylist->head;
displaylist->current = displaylist->head;
-
+
displaylist->head->lcd = create_lcd();
displaylist->head->lcd->mkey_state = 0;
-
+
displaylist->head->prev = displaylist->head;
displaylist->head->next = displaylist->head;
displaylist->head->list = displaylist;
-
+
pthread_mutex_unlock(&lcdlist_mutex);
return displaylist;
}
lcdnode_t *lcdnode_add(lcdlist_t **display_list) {
-
+
lcdnode_t *new = NULL;
-
+
pthread_mutex_lock(&lcdlist_mutex);
-
+
new = g15_xmalloc(sizeof(lcdnode_t));
new->prev = (*display_list)->head;
- new->next = (*display_list)->tail;
+ new->next = (*display_list)->tail;
new->lcd = create_lcd();
new->last_priority = NULL;
-
+
(*display_list)->head->next=new;
(*display_list)->current = new;
-
+
(*display_list)->head = new;
(*display_list)->head->list = *display_list;
-
+
pthread_mutex_unlock(&lcdlist_mutex);
-
+
return new;
}
void lcdnode_remove (lcdnode_t *oldnode) {
-
+
lcdlist_t **display_list = NULL;
lcdnode_t **prev = NULL;
lcdnode_t **next = NULL;
-
+
pthread_mutex_lock(&lcdlist_mutex);
-
+
display_list = &oldnode->list;
prev = &oldnode->prev;
next = &oldnode->next;
-
+
quit_lcd(oldnode->lcd);
-
+
if((*display_list)->current == oldnode) {
if((*display_list)->current!=(*display_list)->head){
(*display_list)->current = oldnode->next;
@@ -123,13 +123,13 @@
}
(*display_list)->current->lcd->state_changed = 1;
}
-
+
if(&oldnode->lcd == keyhandler) {
client_handles_keys = 0;
keyhandler = NULL;
daemon_log(LOG_WARNING,"Client key handler quit, going back to defaults");
}
-
+
if((*display_list)->head!=oldnode){
(*next)->prev = oldnode->prev;
(*prev)->next = oldnode->next;
@@ -139,23 +139,23 @@
}
free(oldnode);
-
+
pthread_mutex_unlock(&lcdlist_mutex);
}
void lcdlist_destroy(lcdlist_t **displaylist) {
-
+
int i = 0;
-
+
while ((*displaylist)->head != (*displaylist)->tail) {
i++;
lcdnode_remove((*displaylist)->head);
}
-
+
free((*displaylist)->tail->lcd);
free((*displaylist)->tail);
free(*displaylist);
-
+
pthread_mutex_destroy(&lcdlist_mutex);
}
Modified: trunk/g15daemon/g15daemon/main.c
===================================================================
--- trunk/g15daemon/g15daemon/main.c 2009-10-17 22:22:46 UTC (rev 523)
+++ trunk/g15daemon/g15daemon/main.c 2010-01-23 18:53:46 UTC (rev 524)
@@ -14,11 +14,11 @@
You should have received a copy of the GNU General Public License
along with g15daemon; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
+
(c) 2006-2007 Mike Lampard, Philip Lawatsch, and others
-
+
$Revision$ - $Date$ $Author$
-
+
This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients.
Client screens can be cycled through by pressing the 'L1' key.
@@ -59,20 +59,20 @@
extern unsigned int connected_clients;
static void *keyboard_watch_thread(void *lcdlist){
-
+
lcdlist_t *displaylist = (lcdlist_t*)(lcdlist);
-
+
static unsigned int lastkeypresses = 0;
unsigned int keypresses = 0;
int retval = 0;
current_key_state = 0;
-
+
while (!leaving) {
-
+
pthread_mutex_lock(&g15lib_mutex);
retval = getPressedKeys(&keypresses, 40);
pthread_mutex_unlock(&g15lib_mutex);
-
+
if(retval == G15_NO_ERROR){
if(keypresses != lastkeypresses){
current_key_state = keypresses;
@@ -82,15 +82,22 @@
lastkeypresses = keypresses;
}
}
- if(retval == -ENODEV && LIBG15_VERSION>=1200) {
- pthread_mutex_lock(&g15lib_mutex);
- while((retval=re_initLibG15() != G15_NO_ERROR) && !leaving){
- daemon_log(LOG_ERR,"Keyboard went away! retrying...");
- sleep(1);
- }
- if(!leaving) { displaylist->current->lcd->state_changed=1; displaylist->current->lcd->ident=random();}
- pthread_mutex_unlock(&g15lib_mutex);
- }
+ if(retval == -ENODEV && LIBG15_VERSION>=1200)
+ {
+ pthread_mutex_lock(&g15lib_mutex);
+ while((retval=re_initLibG15() != G15_NO_ERROR) && !leaving)
+ {
+ daemon_log(LOG_ERR,"Keyboard went away! retrying...");
+ sleep(1);
+ }
+ if(!leaving)
+ {
+ displaylist->current->lcd->state_changed=1;
+ daemon_log(LOG_INFO,"keyboard_watch_thread. state_changed=1 and ident=random()");
+ displaylist->current->lcd->ident=random();
+ }
+ pthread_mutex_unlock(&g15lib_mutex);
+ }
pthread_msleep(10);
}
@@ -101,57 +108,63 @@
lcdlist_t *displaylist = (lcdlist_t*)(lcdlist);
static long int lastlcd = 1;
-
+
lcd_t *displaying = displaylist->tail->lcd;
memset(displaying->buf,0,1024);
-
+
writePixmapToLCD(logo_data);
pthread_sleep(2);
-
+
while (!leaving) {
pthread_mutex_lock(&lcdlist_mutex);
-
+
displaying = displaylist->current->lcd;
-
+
if(displaylist->tail == displaylist->current){
lcdclock(displaying);
displaying->mkey_state = 0;
}
-
+
if(displaying->ident != lastlcd){
+ daemon_log(LOG_INFO,"ident changed is true, updating LCD contents");
write_buf_to_g15(displaying);
lastlcd = displaying->ident;
}
-
+
if(displaying->state_changed ){
+ daemon_log(LOG_INFO,"state_changed is true, updating all LEDs and LCD");
setLCDContrast(displaying->contrast_state);
- if(connected_clients)
- displaying->mkey_state = displaying->mkey_state | G15_LED_MR;
+// if(connected_clients)
+// {
+// displaying->mkey_state = displaying->mkey_state | G15_LED_MR;
+// daemon_log(LOG_INFO,"Adding G15_LED_MR to LEDS shown.");
+// }
setLEDs(displaying->mkey_state);
setLCDBrightness(displaying->backlight_state);
displaying->state_changed = 0;
+ daemon_log(LOG_INFO,"Done updating. state_changed=0");
}
-
+
pthread_mutex_unlock(&lcdlist_mutex);
-
+
pthread_msleep(100);
}
return NULL;
}
-/* this thread only listens for new connections.
+/* this thread only listens for new connections.
* sockserver_accept will spawn a new thread for each connected client
*/
static void *lcdserver_thread(void *lcdlist){
lcdlist_t *displaylist = (lcdlist_t*) lcdlist ;
int g15_socket=-1;
-
+
if((g15_socket = init_sockserver())<0){
daemon_log(LOG_ERR,"Unable to initialise the server at port %i",LISTEN_PORT);
return NULL;
}
-
+
if (fcntl(g15_socket, F_SETFL, O_NONBLOCK) <0 ) {
daemon_log(LOG_ERR,"Unable to set socket to nonblocking");
}
@@ -159,7 +172,7 @@
while ( !leaving ) {
g15_clientconnect(&displaylist,g15_socket);
}
-
+
close(g15_socket);
return NULL;
}
@@ -171,22 +184,22 @@
int retval;
int i;
int g15daemon_debug = 0;
-
+
pthread_t keyboard_thread;
pthread_t lcd_thread;
pthread_t server_thread;
- daemon_pid_file_ident =
- daemon_log_ident =
+ daemon_pid_file_ident =
+ daemon_log_ident =
daemon_ident_from_argv0(argv[0]);
-
+
for (i=0;i<argc;i++) {
char daemonargs[20];
memset(daemonargs,0,20);
strncpy(daemonargs,argv[i],19);
if (!strncmp(daemonargs, "-k",2) || !strncmp(daemonargs, "--kill",6)) {
-#ifdef DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
+#ifdef DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
if ((retval = daemon_pid_file_kill_wait(SIGINT, 15)) != 0)
#else
if ((retval = daemon_pid_file_kill(SIGINT)) != 0)
@@ -195,7 +208,7 @@
return retval < 0 ? 1 : 0;
}
if (!strncmp(daemonargs, "-K",2) || !strncmp(daemonargs, "--KILL",6)) {
-#ifdef DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
+#ifdef DAEMON_PID_FILE_KILL_WAIT_AVAILABLE
if ((retval = daemon_pid_file_kill_wait(SIGUSR1, 15)) != 0)
#else
if ((retval = daemon_pid_file_kill(SIGUSR1)) != 0)
@@ -208,8 +221,8 @@
printf("G15Daemon version %s - %s\n",VERSION,daemon_pid_file_is_running() >= 0 ?"Loaded & Running":"Not Running");
printf("compiled with libg15 version %.3f\n\n",lg15ver/1000);
exit(0);
- }
-
+ }
+
if (!strncmp(daemonargs, "-h",2) || !strncmp(daemonargs, "--help",6)) {
printf("G15Daemon version %s - %s\n",VERSION,daemon_pid_file_is_running() >= 0 ?"Loaded & Running":"Not Running");
printf("%s -h (--help) or -k (--kill) or -s (--switch) or -d (--debug) or -v (--version)\n\n -k will kill a previous incarnation",argv[0]);
@@ -229,6 +242,9 @@
cycle_key = G15_KEY_MR;
}
+// Uncomment when debugging if you want L1 as switch key (which I think is the only sane option)
+// cycle_key = G15_KEY_L1;
+
if (!strncmp(daemonargs, "-d",2) || !strncmp(daemonargs, "--debug",7)) {
g15daemon_debug = 1;
if((argv[i+1])!=NULL)
@@ -253,7 +269,7 @@
return 1;
}
}
-
+
if (daemonpid && !g15daemon_debug){
retval=0;
char * g15_errors[] = { "No Error",
@@ -261,13 +277,13 @@
"Unable to initialise keyboard",
"Unable to configure the linux kernel UINPUT driver",
"Unable to register signal handler",
- "Unable to create new keyboard thread",
+ "Unable to create new keyboard thread",
"Unable to create new display thread",
"Unable to create server thread",
#ifdef OSTYPE_DARWIN
"Unable to load USB shield kext",
"Unable to launch kextload",
-#endif
+#endif
NULL };
if((retval = daemon_retval_wait(20)) !=0) {
if(retval)
@@ -276,9 +292,9 @@
daemon_log(LOG_ERR,"A library error occurred. Please file a bug report stating the g15daemon version, your kernel version, libdaemon version and your distribution name.");
return 255;
}
-
+
return retval;
-
+
}else{ /* daemonised now */
int fd;
@@ -286,13 +302,13 @@
lcdlist_t *lcdlist;
pthread_attr_t attr;
struct passwd *nobody;
- int disable_kb_backlight_onexit = 0;
-
+ int disable_kb_backlight_onexit = 0;
+
nobody = getpwnam("nobody");
-
+
if(daemon_pid_file_create() !=0){
daemon_log(LOG_ERR,"Unable to create PID File! Exiting");
- daemon_retval_send(1);
+ daemon_retval_send(1);
goto exitnow;
}
@@ -301,10 +317,10 @@
libg15Debug(g15daemon_debug);
#ifdef OSTYPE_DARWIN
-
+
/* OS X: load codeless kext */
retval = system("/sbin/kextload " "/System/Library/Extensions/libusbshield.kext");
-
+
if (WIFEXITED(retval)){
if (WEXITSTATUS(retval) !=0){
daemon_log(LOG_ERR,"Unable to load USB shield kext");
@@ -323,9 +339,9 @@
goto exitnow;
}
- setLCDContrast(1);
+ setLCDContrast(1);
setLEDs(0);
- setLCDBrightness(1);
+ setLCDBrightness(1);
#ifdef LIBG15_VERSION
#if LIBG15_VERSION >= 1200
setKBBrightness(1);
@@ -342,7 +358,7 @@
daemon_retval_send(3);
goto exitnow;
}
-
+
if(daemon_signal_init(SIGINT,SIGQUIT,SIGHUP,SIGPIPE,SIGUSR1,0) <0){
daemon_log(LOG_ERR,"Unable to register signal handler. Exiting");
daemon_retval_send(4);
@@ -366,7 +382,7 @@
daemon_retval_send(5);
goto exitnow;
}
- pthread_attr_setstacksize(&attr,128*1024);
+ pthread_attr_setstacksize(&attr,128*1024);
if (pthread_create(&lcd_thread, &attr, lcd_draw_thread, lcdlist) != 0) {
daemon_log(LOG_ERR,"Unable to create display thread. Exiting");
@@ -383,14 +399,14 @@
daemon_log(LOG_INFO,"%s loaded\n",PACKAGE_STRING);
FD_ZERO(&fds);
FD_SET(fd=daemon_signal_fd(),&fds);
-
+
do {
fd_set myfds = fds;
if(select(FD_SETSIZE,&myfds,0,0,0) <0){
if(errno == EINTR) continue;
break;
}
-
+
if(FD_ISSET(fd,&fds)){
int sig;
sig = daemon_signal_next();
@@ -407,7 +423,7 @@
}
}
} while ( leaving == 0 );
-
+
daemon_signal_done();
pthread_join(server_thread,NULL);
pthread_join(lcd_thread,NULL);
@@ -417,7 +433,7 @@
memset(blank,0,G15_BUFFER_LEN);
writePixmapToLCD(blank);
free(blank);
- setLCDBrightness(0);
+ setLCDBrightness(0);
#ifdef LIBG15_VERSION
#if LIBG15_VERSION >= 1200
if(disable_kb_backlight_onexit)
@@ -430,7 +446,7 @@
#endif
#ifdef LIBG15_VERSION
#if LIBG15_VERSION >= 1100
- exitLibG15();
+ exitLibG15();
#endif
#endif
lcdlist_destroy(&lcdlist);
Modified: trunk/g15daemon/g15daemon/utility_funcs.c
===================================================================
--- trunk/g15daemon/g15daemon/utility_funcs.c 2009-10-17 22:22:46 UTC (rev 523)
+++ trunk/g15daemon/g15daemon/utility_funcs.c 2010-01-23 18:53:46 UTC (rev 524)
@@ -14,11 +14,11 @@
You should have received a copy of the GNU General Public License
along with g15daemon; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
+
(c) 2006-2007 Mike Lampard, Philip Lawatsch, and others
$Revision$ - $Date$ $Author$
-
+
This daemon listens on localhost port 15550 for client connections,
and arbitrates LCD display. Allows for multiple simultaneous clients.
Client screens can be cycled through by pressing the 'L1' key.
@@ -58,8 +58,8 @@
#endif
void g15_process_keys(lcdlist_t *displaylist, unsigned int currentkeys, unsigned int lastkeys){
-
+
/* 'G' keys */
if(!client_handles_keys) {
if((currentkeys & G15_KEY_G1) && !(lastkeys & G15_KEY_G1))
@@ -191,7 +191,7 @@
displaylist->current = displaylist->head;
else
displaylist->current = displaylist->current->prev;
- }
+ }
while (current_screen != displaylist->current);
if(displaylist->tail == displaylist->current) {
displaylist->current = displaylist->head;
@@ -200,19 +200,20 @@
}
displaylist->current->lcd->usr_foreground = 1;
displaylist->current->lcd->state_changed = 1;
+ daemon_log(LOG_INFO,"L1 pressed. state_changed=1 for current->lcd");
displaylist->current->last_priority = displaylist->current;
pthread_mutex_unlock(&lcdlist_mutex);
}
}
-
+
/* 'L' keys... */
- if(cycle_key!=G15_KEY_L1) {
+ if(cycle_key!=G15_KEY_L1) {
if((currentkeys & G15_KEY_L1) && !(lastkeys & G15_KEY_L1))
keydown(LKEY_OFFSET);
else if(!(currentkeys & G15_KEY_L1) && (lastkeys & G15_KEY_L1))
keyup(LKEY_OFFSET);
}
-
+
if((currentkeys & G15_KEY_L2) && !(lastkeys & G15_KEY_L2))
keydown(LKEY_OFFSET+1);
else if(!(currentkeys & G15_KEY_L2) && (lastkeys & G15_KEY_L2))
@@ -257,8 +258,8 @@
for(y=0;y<43;y++)
setpixel(lcd,x,y,orig_buf[x+(y*160)]);
}
-
+
/* wrap the libg15 function */
void write_buf_to_g15(lcd_t *lcd)
{
@@ -291,7 +292,7 @@
/* millisecond sleep routine. */
int pthread_msleep(int milliseconds) {
-
+
struct timespec timeout;
if(milliseconds>999)
milliseconds=999;
@@ -309,25 +310,25 @@
int narrows=0;
int totalwidth=0;
char buf[10];
-
+
time_t currtime = time(NULL);
-
- if(lcd->ident < currtime - 60) {
+
+ if(lcd->ident < currtime - 60) {
memset(lcd->buf,0,1024);
memset(buf,0,10);
strftime(buf,6,"%H:%M",localtime(&currtime));
- if(buf[0]==49)
+ if(buf[0]==49)
narrows=1;
- len = strlen(buf);
+ len = strlen(buf);
if(narrows)
totalwidth=(len*20)+(15);
else
totalwidth=len*20;
- for (col=0;col<len;col++)
+ for (col=0;col<len;col++)
{
draw_bignum (lcd, (80-(totalwidth)/2)+col*20, 1,(80-(totalwidth)/2)+(col+1)*20, LCD_HEIGHT, BLACK, buf[col]);
@@ -338,10 +339,10 @@
/* the client must send 6880 bytes for each lcd screen. This thread will continue to copy data
-* into the clients LCD buffer for as long as the connection remains open.
+* into the clients LCD buffer for as long as the connection remains open.
* so, the client should open a socket, check to ensure that the server is a g15daemon,
-* and send multiple 6880 byte packets (1 for each screen update)
-* once the client disconnects by closing the socket, the LCD buffer is
+* and send multiple 6880 byte packets (1 for each screen update)
+* once the client disconnects by closing the socket, the LCD buffer is
* removed and will no longer be displayed.
*/
void *lcd_client_thread(void *display) {
@@ -355,11 +356,15 @@
int client_sock = client_lcd->connection;
char helo[]=SERV_HELO;
unsigned char *tmpbuf=g15_xmalloc(6880);
-
- if(!connected_clients)
- setLEDs(G15_LED_MR); /* turn on the MR backlight to show that it's now being used for lcd-switching */
+
+// if(!connected_clients)
+// {
+// daemon_log(LOG_INFO,"Seting LEDs to MR");
+// setLEDs(G15_LED_MR); /*
+// turn on the MR backlight to show that it's now being used for lcd-switching */
+// }
connected_clients++;
-
+
if(g15_send(client_sock, (char*)helo, strlen(SERV_HELO))<0){
goto exitthread;
}
@@ -375,7 +380,7 @@
break;
}
pthread_mutex_lock(&lcdlist_mutex);
- memset(client_lcd->buf,0,1024);
+ memset(client_lcd->buf,0,1024);
convert_buf(client_lcd,tmpbuf);
client_lcd->ident = random();
pthread_mutex_unlock(&lcdlist_mutex);
@@ -383,8 +388,12 @@
}
else if (tmpbuf[0]=='R') { /* libg15render buffer */
while(!leaving) {
+ daemon_log(LOG_INFO,"loop: libg15render lcd thread");
retval = g15_recv(g15node, client_sock, (char *)tmpbuf, 1048);
- if(retval != 1048) {
+ daemon_log(LOG_INFO,"loop: libg15render lcd thread2");
+ if(retval != 1048)
+ {
+ daemon_log(LOG_INFO,"libg15render lcd thread exiting");
break;
}
pthread_mutex_lock(&lcdlist_mutex);
@@ -408,18 +417,18 @@
height = tmpbuf[3];
header = 4;
}
-
+
buflen = (width/8)*height;
if(buflen>860){ /* grab the remainder of the image and discard excess bytes */
/* retval=g15_recv(client_sock,(char*)tmpbuf+865,buflen-860); */
- retval=g15_recv(g15node, client_sock,NULL,buflen-860);
+ retval=g15_recv(g15node, client_sock,NULL,buflen-860);
buflen = 860;
}
-
+
if(width!=160) /* FIXME - we ought to scale images I suppose */
goto exitthread;
-
+
pthread_mutex_lock(&lcdlist_mutex);
memcpy(client_lcd->buf,tmpbuf+header,buflen+header);
client_lcd->ident = random();
@@ -478,7 +487,7 @@
}
}
-
+
pthread_detach(client_connection);
}
return 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|