#include <stdio.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include <gtk/gtk.h>
#include "connections.h"
#include "parser.h"
#include "global.h"
#include "ipdcGui.h"
Go to the source code of this file.
Defines | |
#define | UI_fILE "iPDC.glade" |
#define | GW(name) CH_GET_WIDGET(builder, name, data) |
Functions | |
int | main (int argc, char **argv) |
int main | ( | int | argc, | |
char ** | argv | |||
) |
Definition at line 53 of file ipdc.c.
References about_ipdc(), _ChData::about_menuitem, add_new_pdc(), _ChData::add_pdc_button, add_pmu(), _ChData::add_pmu_button, _ChData::cmd_cfg_button, _ChData::cmd_data_off_button, _ChData::cmd_data_on_button, cmd_or_remove_pmu(), connection_table(), data, destroy(), _ChData::display_conn_table_button, display_pdc_detail(), _ChData::enter_pdc_detail_menuitem, _ChData::exit_button, _ChData::exit_menuitem, fill_pdc_details(), fp_log, GW, _ChData::ipdc, ipdc_colors(), p_thread, pdc_details(), _ChData::pdc_details_menuitem, remove_pdc(), _ChData::remove_pdc_button, _ChData::remove_pmu_button, TCP_thread, tname, UDP_thread, UI_fILE, UL_TCP_sockfd, and UL_UDP_sockfd.
00054 { 00055 DIR *dip; 00056 struct dirent *dit; 00057 memset(tname,'\0',20); 00058 strcpy(tname,"/dev/pts/"); 00059 00060 GtkBuilder *builder; 00061 GError *error = NULL; 00062 00063 system("gnome-terminal"); 00064 sleep(1); 00065 00066 /* DIR *opendir(const char *name); 00067 * 00068 * Open a directory stream to argv[1] and make sure 00069 * it's a readable and valid (directory) */ 00070 if ((dip = opendir(tname)) == NULL) 00071 { 00072 perror("opendir"); 00073 return 0; 00074 } 00075 00076 printf("Directory stream is now open\n"); 00077 00078 /* struct dirent *readdir(DIR *dir); 00079 * 00080 * Read in the files from argv[1] and print */ 00081 while ((dit = readdir(dip)) != NULL) 00082 { 00083 if(!strchr(dit->d_name,'.')) { 00084 printf("\n%s", dit->d_name); 00085 break; 00086 00087 } 00088 } 00089 00090 strcat(tname,dit->d_name); 00091 00092 /* int closedir(DIR *dir); 00093 * 00094 * Close the stream to argv[1]. And check for errors. */ 00095 if (closedir(dip) == -1) 00096 { 00097 perror("closedir"); 00098 return 0; 00099 } 00100 00101 printf("\nDirectory stream is now closed\n"); 00102 00103 fp_log = fopen(tname,"w"); 00104 00105 if(fp_log == NULL) 00106 printf("\n fp null\n"); 00107 else 00108 fprintf(fp_log,"fp not null\n"); 00109 00110 system("clear"); 00111 00112 /* Init GTK+ */ 00113 gtk_init(&argc, &argv); 00114 00115 /* Create new GtkBuilder object */ 00116 builder = gtk_builder_new(); 00117 00118 if(!gtk_builder_add_from_file(builder, UI_fILE, &error)) 00119 { 00120 g_warning("%s", error->message); 00121 g_free(error); 00122 return(1); 00123 } 00124 00125 /* Allocate data structure */ 00126 data = g_slice_new(ChData); 00127 00128 /* Get objects from UI */ 00129 #define GW(name) CH_GET_WIDGET(builder, name, data) 00130 GW(ipdc); 00131 GW(add_pmu_button); 00132 GW(remove_pmu_button); 00133 GW(cmd_data_off_button); 00134 GW(cmd_data_on_button); 00135 GW(cmd_cfg_button); 00136 GW(add_pdc_button); 00137 GW(remove_pdc_button); 00138 GW(display_conn_table_button); 00139 GW(enter_pdc_detail_menuitem); 00140 GW(exit_button); 00141 GW(time_label); 00142 GW(time_label1); 00143 GW(menubar); 00144 GW(pdc_details_menuitem); 00145 GW(exit_menuitem); 00146 GW(about_menuitem); 00147 GW(welcome_ipdc); 00148 GW(img_label); 00149 GW(footer_label); 00150 GW(admin_label); 00151 GW(wecome_button); 00152 #undef GW 00153 00154 /* Connect signals */ 00155 gtk_builder_connect_signals(builder, data); 00156 00157 /* Connect signals */ 00158 gtk_builder_connect_signals(builder, NULL); 00159 00160 /* fill the iPDC details */ 00161 fill_pdc_details (); 00162 00163 /* Decorate the main window of iPDC */ 00164 ipdc_colors(); 00165 00166 /* Signals Definitions*/ 00167 g_signal_connect (data->ipdc, "destroy", G_CALLBACK(destroy), NULL); 00168 g_signal_connect (data->add_pmu_button, "clicked", G_CALLBACK(add_pmu), NULL); 00169 g_signal_connect (data->remove_pmu_button, "clicked", G_CALLBACK(cmd_or_remove_pmu), (gpointer) "1"); 00170 g_signal_connect (data->cmd_data_off_button, "clicked", G_CALLBACK(cmd_or_remove_pmu), (gpointer) "2"); 00171 g_signal_connect (data->cmd_data_on_button, "clicked", G_CALLBACK(cmd_or_remove_pmu), (gpointer) "3"); 00172 g_signal_connect (data->cmd_cfg_button, "clicked", G_CALLBACK(cmd_or_remove_pmu), (gpointer) "4"); 00173 g_signal_connect (data->add_pdc_button, "clicked", G_CALLBACK(add_new_pdc), NULL); 00174 g_signal_connect (data->remove_pdc_button, "clicked", G_CALLBACK(remove_pdc), NULL); 00175 g_signal_connect (data->display_conn_table_button, "clicked", G_CALLBACK(connection_table), NULL); 00176 g_signal_connect (data->exit_button, "clicked", G_CALLBACK(destroy), NULL); 00177 g_signal_connect (data->pdc_details_menuitem, "button_press_event", G_CALLBACK(display_pdc_detail), NULL); 00178 g_signal_connect (data->enter_pdc_detail_menuitem, "button_press_event", G_CALLBACK(pdc_details), NULL); 00179 g_signal_connect (data->exit_menuitem, "button_press_event", G_CALLBACK(destroy), NULL); 00180 g_signal_connect (data->about_menuitem, "button_press_event", G_CALLBACK(about_ipdc), NULL); 00181 00182 /* Destroy builder, since we don't need it anymore */ 00183 g_object_unref(G_OBJECT(builder)); 00184 00185 /* Show window. All other widgets are automatically shown by GtkBuilder */ 00186 gtk_widget_show(data->ipdc); 00187 00188 /* GTK Main */ 00189 gtk_main(); 00190 00191 pthread_join(UDP_thread, NULL); 00192 pthread_join(TCP_thread, NULL); 00193 pthread_join(p_thread, NULL); 00194 00195 close(UL_UDP_sockfd); 00196 close(UL_TCP_sockfd); 00197 00198 /* Free any allocated data */ 00199 g_slice_free(ChData, data); 00200 00201 return(0); 00202 }