|
Last change
on this file since a87727a was
c5c522c,
checked in by Edwin Eefting <edwin@datux.nl>, 9 years ago
|
|
initial commit, transferred from cleaned syn3 svn tree
|
-
Property mode set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | client_data.c |
|---|
| 3 | |
|---|
| 4 | Creates and destroys a client's data structures. These are mainly |
|---|
| 5 | its name, screen list, and menu list. |
|---|
| 6 | |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | #include <stdlib.h> |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include <string.h> |
|---|
| 13 | |
|---|
| 14 | #include "../shared/debug.h" |
|---|
| 15 | |
|---|
| 16 | #include "client_data.h" |
|---|
| 17 | #include "screen.h" |
|---|
| 18 | #include "screenlist.h" |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | int client_data_init(client_data *d) |
|---|
| 23 | { |
|---|
| 24 | if(!d) return -1; |
|---|
| 25 | |
|---|
| 26 | d->ack = 0; |
|---|
| 27 | d->name = NULL; |
|---|
| 28 | |
|---|
| 29 | d->screenlist = LL_new(); |
|---|
| 30 | if(!d->screenlist) |
|---|
| 31 | { |
|---|
| 32 | fprintf(stderr, "client_data_init: Error allocating screenlist\n"); |
|---|
| 33 | return -1; |
|---|
| 34 | } |
|---|
| 35 | /* TODO: this section... (client menus) |
|---|
| 36 | d->menulist = LL_new(); |
|---|
| 37 | if(!d->menulist) |
|---|
| 38 | { |
|---|
| 39 | fprintf(stderr, "client_data_init: Error allocating menulist\n"); |
|---|
| 40 | return -1; |
|---|
| 41 | } |
|---|
| 42 | */ |
|---|
| 43 | return 0; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | int client_data_destroy(client_data *d) |
|---|
| 47 | { |
|---|
| 48 | screen *s; |
|---|
| 49 | |
|---|
| 50 | debug("client_data_destroy\n"); |
|---|
| 51 | |
|---|
| 52 | if(!d) return -1; |
|---|
| 53 | |
|---|
| 54 | d->ack = 0; |
|---|
| 55 | |
|---|
| 56 | // Clean up the name... |
|---|
| 57 | if(d->name) |
|---|
| 58 | free(d->name); |
|---|
| 59 | |
|---|
| 60 | // Clean up the screenlist... |
|---|
| 61 | debug("client_data_destroy: Cleaning screenlist\n"); |
|---|
| 62 | LL_Rewind(d->screenlist); |
|---|
| 63 | do { |
|---|
| 64 | s = (screen *)LL_Get(d->screenlist); |
|---|
| 65 | if(s) |
|---|
| 66 | { |
|---|
| 67 | debug("client_data_destroy: removing screen %s\n", s->id); |
|---|
| 68 | |
|---|
| 69 | // FIXME? This shouldn't be handled here... |
|---|
| 70 | // Now, remove it from the screenlist... |
|---|
| 71 | if(screenlist_remove_all(s) < 0) |
|---|
| 72 | { |
|---|
| 73 | // Not a serious error.. |
|---|
| 74 | fprintf(stderr, "client_data_destroy: Error dequeueing screen\n"); |
|---|
| 75 | return 0; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | // Free its memory... |
|---|
| 79 | screen_destroy(s); |
|---|
| 80 | } |
|---|
| 81 | } while(LL_Next(d->screenlist) == 0); |
|---|
| 82 | LL_Destroy(d->screenlist); |
|---|
| 83 | |
|---|
| 84 | // TODO: clean up the rest of the data... |
|---|
| 85 | |
|---|
| 86 | return 0; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.