/[pcsx2_0.9.7]/trunk/common/include/PS2Eext.h
ViewVC logotype

Annotation of /trunk/common/include/PS2Eext.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (hide annotations) (download)
Sat Dec 25 02:51:30 2010 UTC (9 years, 7 months ago) by william
File MIME type: text/plain
File size: 6986 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4139 local: v0.9.7.283-latest) in ./trunk
1 william 31 /* PCSX2 - PS2 Emulator for PCs
2     * Copyright (C) 2002-2010 PCSX2 Dev Team
3     *
4     * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5     * of the GNU Lesser General Public License as published by the Free Software Found-
6     * ation, either version 3 of the License, or (at your option) any later version.
7     *
8     * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10     * PURPOSE. See the GNU General Public License for more details.
11     *
12     * You should have received a copy of the GNU General Public License along with PCSX2.
13     * If not, see <http://www.gnu.org/licenses/>.
14     */
15    
16     #ifndef PS2EEXT_H_INCLUDED
17     #define PS2EEXT_H_INCLUDED
18    
19     #include <stdio.h>
20     #include <string>
21     #include <cstdarg>
22    
23     #ifdef _MSC_VER
24     #include <windows.h>
25     #include <windowsx.h>
26     #include <commctrl.h>
27    
28     #define EXPORT_C_(type) extern "C" type CALLBACK
29     #else
30     #include <gtk/gtk.h>
31     #include <cstring>
32    
33 william 62 #define EXPORT_C_(type) extern "C" __attribute__((externally_visible,visibility("default"))) type
34 william 31 #endif
35    
36     //#include "PS2Edefs.h"
37    
38     static void SysMessage(const char *fmt, ...);
39     static void __forceinline PluginNullConfigure(std::string desc, s32 &log);
40     static void __forceinline PluginNullAbout(const char *aboutText);
41    
42     enum FileMode
43     {
44     READ_FILE = 0,
45     WRITE_FILE
46     };
47    
48     struct PluginLog
49     {
50     bool WriteToFile, WriteToConsole;
51     FILE *LogFile;
52    
53     bool Open(std::string logname)
54     {
55     LogFile = fopen(logname.c_str(), "w");
56    
57     if (LogFile)
58     {
59     setvbuf(LogFile, NULL, _IONBF, 0);
60     return true;
61     }
62     return false;
63     }
64    
65     void Close()
66     {
67 william 62 if (LogFile) {
68     fclose(LogFile);
69     LogFile = NULL;
70     }
71 william 31 }
72    
73     void Write(const char *fmt, ...)
74     {
75     va_list list;
76    
77     if (LogFile == NULL) return;
78    
79     va_start(list, fmt);
80     if (WriteToFile) vfprintf(LogFile, fmt, list);
81     if (WriteToConsole) vfprintf(stdout, fmt, list);
82     va_end(list);
83     }
84    
85     void WriteLn(const char *fmt, ...)
86     {
87     va_list list;
88    
89     if (LogFile == NULL) return;
90    
91     va_start(list, fmt);
92     if (WriteToFile) vfprintf(LogFile, fmt, list);
93     if (WriteToConsole) vfprintf(stdout, fmt, list);
94     va_end(list);
95    
96     if (WriteToFile) fprintf(LogFile, "\n");
97     if (WriteToConsole) fprintf(stdout, "\n");
98     }
99    
100     void Message(const char *fmt, ...)
101     {
102     va_list list;
103     char buf[256];
104    
105     if (LogFile == NULL) return;
106    
107     va_start(list, fmt);
108     vsprintf(buf, fmt, list);
109     va_end(list);
110    
111     SysMessage(buf);
112     }
113     };
114    
115     struct PluginConf
116     {
117     FILE *ConfFile;
118     char *PluginName;
119    
120     bool Open(std::string name, FileMode mode = READ_FILE)
121     {
122     if (mode == READ_FILE)
123     {
124     ConfFile = fopen(name.c_str(), "r");
125     }
126     else
127     {
128     ConfFile = fopen(name.c_str(), "w");
129     }
130    
131     if (ConfFile == NULL) return false;
132    
133     return true;
134     }
135    
136     void Close()
137     {
138 william 62 if (ConfFile) {
139     fclose(ConfFile);
140     ConfFile = NULL;
141     }
142 william 31 }
143    
144     int ReadInt(const std::string& item, int defval)
145     {
146     int value = defval;
147     std::string buf = item + " = %d\n";
148    
149     if (ConfFile) fscanf(ConfFile, buf.c_str(), &value);
150    
151     return value;
152     }
153    
154     void WriteInt(std::string item, int value)
155     {
156     std::string buf = item + " = %d\n";
157    
158     if (ConfFile) fprintf(ConfFile, buf.c_str(), value);
159     }
160     };
161    
162     #ifdef __LINUX__
163    
164     static void SysMessage(const char *fmt, ...)
165     {
166     va_list list;
167     char msg[512];
168    
169     va_start(list, fmt);
170     vsprintf(msg, fmt, list);
171     va_end(list);
172    
173     if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
174    
175     GtkWidget *dialog;
176     dialog = gtk_message_dialog_new (NULL,
177     GTK_DIALOG_DESTROY_WITH_PARENT,
178     GTK_MESSAGE_INFO,
179     GTK_BUTTONS_OK,
180     "%s", msg);
181     gtk_dialog_run (GTK_DIALOG (dialog));
182     gtk_widget_destroy (dialog);
183     }
184    
185     static bool loggingValue = false;
186    
187     static void __forceinline set_logging(GtkToggleButton *check)
188     {
189     loggingValue = gtk_toggle_button_get_active(check);
190     }
191    
192     static void __forceinline send_ok(GtkDialog *dialog)
193     {
194     int ret = (loggingValue) ? 1 : 0;
195     gtk_dialog_response (dialog, ret);
196     }
197    
198     static void __forceinline PluginNullConfigure(std::string desc, int &log)
199     {
200     GtkWidget *dialog, *label, *okay_button, *check_box;
201    
202     /* Create the widgets */
203     dialog = gtk_dialog_new();
204     label = gtk_label_new (desc.c_str());
205     okay_button = gtk_button_new_with_label("Ok");
206     check_box = gtk_check_button_new_with_label("Logging");
207    
208     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_box), (log != 0));
209    
210     /* Ensure that the dialog box is destroyed when the user clicks ok, and that we get the check box value. */
211     g_signal_connect_swapped(GTK_OBJECT (okay_button), "clicked", G_CALLBACK(send_ok), dialog);
212     g_signal_connect_swapped(GTK_OBJECT (check_box), "toggled", G_CALLBACK(set_logging), check_box);
213    
214     /* Add all our widgets, and show everything we've added to the dialog. */
215 william 290 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_action_area(GTK_DIALOG(dialog))), okay_button);
216     gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), label);
217     gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(dialog))), check_box);
218 william 31 gtk_widget_show_all (dialog);
219    
220     log = gtk_dialog_run (GTK_DIALOG (dialog));
221     gtk_widget_destroy (dialog);
222     }
223    
224     static void __forceinline PluginNullAbout(const char *aboutText)
225     {
226     SysMessage(aboutText);
227     }
228    
229     #define ENTRY_POINT /* We don't need no stinkin' entry point! */
230    
231     #else
232    
233     #define usleep(x) Sleep(x / 1000)
234    
235     static void __forceinline SysMessage(const char *fmt, ...)
236     {
237     va_list list;
238     char tmp[512];
239     va_start(list,fmt);
240     vsprintf(tmp,fmt,list);
241     va_end(list);
242     MessageBox( GetActiveWindow(), tmp, "Message", MB_SETFOREGROUND | MB_OK );
243     }
244    
245     static void __forceinline PluginNullConfigure(std::string desc, s32 &log)
246     {
247     /* To do: Write a dialog box that displays a dialog box with the text in desc,
248     and a check box that says "Logging", checked if log !=0, and set log to
249     1 if it is checked on return, and 0 if it isn't. */
250     SysMessage("This space intentionally left blank.");
251     }
252    
253     static void __forceinline PluginNullAbout(const char *aboutText)
254     {
255     SysMessage(aboutText);
256     }
257    
258     #define ENTRY_POINT \
259     HINSTANCE hInst; \
260     \
261     BOOL APIENTRY DllMain(HANDLE hModule, /* DLL INIT*/ \
262     DWORD dwReason, \
263     LPVOID lpReserved) \
264     { \
265     hInst = (HINSTANCE)hModule; \
266     return TRUE; /* very quick :)*/ \
267     }
268    
269     #endif
270     #endif // PS2EEXT_H_INCLUDED

  ViewVC Help
Powered by ViewVC 1.1.22