00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include <signal.h>
00032 #include <sys/ipc.h>
00033 #include <sys/shm.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <dirent.h>
00037 #include <errno.h>
00038 #include <sys/types.h>
00039 #include <unistd.h>
00040 #include <pthread.h>
00041 #include <gtk/gtk.h>
00042 #include "PmuGui.h"
00043 #include "ServerFunction.h"
00044 #include "CfgGuiFunctions.h"
00045 #include "CfgFunction.h"
00046
00047 #define UI_fILE "pmu.glade"
00048
00049
00050
00051
00052
00053 int main(int argc, char **argv)
00054 {
00055
00056 GtkBuilder *builder;
00057 GError *error = NULL;
00058
00059 pid = fork();
00060 if (pid == 0)
00061 {
00062
00063 start_server();
00064 }
00065 else
00066 {
00067
00068
00069
00070 gtk_init(&argc, &argv);
00071
00072
00073 builder = gtk_builder_new();
00074
00075
00076 if(!gtk_builder_add_from_file(builder, UI_fILE, &error))
00077 {
00078 g_warning("%s", error->message);
00079 g_free(error);
00080 return(1);
00081 }
00082
00083
00084 pmu_data = g_slice_new(pmuStruct);
00085
00086
00087 #define GW(name) CH_GET_WIDGET(builder, name, pmu_data)
00088 GW(Pmu_Simulator);
00089 GW(create_cfg_button);
00090 GW(header_frm_button);
00091 GW(pmu_details_button);
00092 GW(cfg_modification_button);
00093 GW(pmu_menubar);
00094 GW(img_label);
00095 GW(welcome_pmu);
00096 GW(admin_label);
00097 GW(logo_butun);
00098 GW(exit_button);
00099 GW(footer_label);
00100 GW(about_menuitem);
00101 GW(exit_menuitem);
00102 GW(E_button);
00103 #undef GW
00104
00105
00106 gtk_builder_connect_signals(builder, pmu_data);
00107 gtk_builder_connect_signals(builder, NULL);
00108
00109
00110 gtk_window_set_title (GTK_WINDOW (pmu_data->Pmu_Simulator), "PMU Simulator");
00111
00112
00113 FILE *file_1 = fopen ("PmuServer.txt","rb");
00114 if (file_1 == NULL)
00115 {
00116 pmu_server();
00117 }
00118 else
00119 {
00120 fclose(file_1);
00121
00122 }
00123
00124
00125 file_1 = fopen ("cfg2.bin","rb");
00126 if (file_1 != NULL)
00127 {
00128 fclose(file_1);
00129 create_cfg();
00130
00131
00132 gtk_widget_set_sensitive(GTK_WIDGET(pmu_data->create_cfg_button), FALSE);
00133 }
00134 else
00135 {
00136
00137 gtk_widget_set_sensitive(GTK_WIDGET(pmu_data->header_frm_button), FALSE);
00138 gtk_widget_set_sensitive(GTK_WIDGET(pmu_data->pmu_details_button), FALSE);
00139 gtk_widget_set_sensitive(GTK_WIDGET(pmu_data->cfg_modification_button), FALSE);
00140 }
00141
00142
00143 pmu_colors();
00144
00145
00146 g_signal_connect (pmu_data->create_cfg_button, "clicked", G_CALLBACK(cfg_create_function), NULL);
00147 g_signal_connect (pmu_data->header_frm_button, "clicked", G_CALLBACK(hdr_create_function), NULL);
00148 g_signal_connect (pmu_data->cfg_modification_button, "clicked", G_CALLBACK(cfg_chng_options), NULL);
00149 g_signal_connect (pmu_data->pmu_details_button, "clicked", G_CALLBACK(show_pmu_details), NULL);
00150 g_signal_connect (pmu_data->exit_button, "clicked", G_CALLBACK (destroy), NULL);
00151 g_signal_connect (pmu_data->about_menuitem, "button_press_event", G_CALLBACK(about_pmu), NULL);
00152 g_signal_connect (pmu_data->exit_menuitem, "button_press_event", G_CALLBACK(destroy), NULL);
00153 g_signal_connect (pmu_data->E_button, "clicked", G_CALLBACK(destroy), NULL);
00154 g_signal_connect_swapped (pmu_data->Pmu_Simulator, "destroy", G_CALLBACK (destroy), NULL);
00155
00156
00157 g_object_unref(G_OBJECT(builder));
00158
00159
00160 gtk_widget_show(pmu_data->Pmu_Simulator);
00161
00162
00163 gtk_main();
00164
00165
00166 g_slice_free(pmuStruct, pmu_data);
00167 }
00168 return(0);
00169 }
00170
00171
00172