⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog_defs.h

📁 用于使用moden进行传真的源代码
💻 H
字号:
/* Copyright (C) 2001 to 2004 Chris VineThis program is distributed under the General Public Licence, version 2.For particulars of this and relevant disclaimers see the fileCOPYING distributed with the source files.*/#ifndef PROG_DEFS_H#define PROG_DEFS_H#include <unistd.h>#include "config.h"// deal with any configuration issues arising from config.h#ifndef HAVE_BOOLtypedef int bool;const bool false = 0;const bool true = 1;#endif#ifndef ENABLE_NLSinline const char* gettext(const char* text) {  return text;}#endif#ifndef HAVE_SSIZE_Ttypedef signed int ssize_t;#endif#ifndef HAVE_SOCKLEN_Ttypedef unsigned int socklen_t;#endif// deal with libsigc++#if GTKMM_VERSION < 24#include "sigc_compatibility.h"#endif// define some common exit codes#define MEM_ERROR 10#define CONFIG_ERROR 11#define COM_ERROR 12#define FILEOPEN_ERROR 13#define PIPE_ERROR 14#define TERM_ERROR 15#define ARG_ERROR 16#define EXEC_ERROR 17#define FORK_ERROR 18#define RC_FILE "efax-gtkrc"#include <vector>#include <string>#include <glibmm/ustring.h>#include <glibmm/refptr.h>#include <gdkmm/pixbuf.h>// forward declaration for pointer to Glib::Mutex in struct Prog_confignamespace Glib {  class Mutex;}using namespace std;    // until I get a Std C++ compliant compiler to test with#define MAX_TEMP_NAME 12/************************* threading issues *************************1. This program uses certain functions which are not guaranteed by   IEEE Std 1003.1 to be thread safe, and which are not protected by   mutexes because this program only uses them in one thread.  These   functions are:     localtime() - used in the main (GUI) thread (efax_controller.cpp)     readdir()   - used in the main (GUI) thread (fax_list.cpp)     gethostbyaddr() ) used in the socket server thread (socket_server.cpp)     gethostbyname() )   If the program is modified to use any of these in a different thread,   mutexes will need to be applied.2. The last member of the Prog_config class below is a pointer to a mutex object   allocated in int main() in main.cpp.  The mutex should be locked whenever:   (a) the main (GUI) thread is modifying a member of the Prog_config class, or   (b) any worker thread is reading the Prog_config object.   No worker thread should modify a Prog_config class member, to save excessive   locking in this program3. In addition, members of the Prog_config class which are not built-in types,   and for which concurrent reads in different threads are not guaranteed, are   read outside the main (GUI) thread as follows -     - Prog_config::resolution is read by EfaxController::get_gs_parms()       (in efax_controller.cpp)     - Prog_config::page_size is read by EfaxController::get_gs_parms()       (in efax_controller.cpp) and by FaxListDialog::get_fax_to_ps_parms() (in       fax_list.cpp)     - Prog_config::page_dim is read by FaxListDialog::get_fax_to_ps_parms() (in       fax_list.cpp)     - Prog_config::print_shrink is read by FaxListDialog::get_fax_to_ps_parms()       (in fax_list.cpp)     - Prog_config::print_cmd is read by FaxListDialog::get_print_from_stdin_parms()       (in fax_list.cpp)     - Prog_config::ps_view_cmd is read by FaxListDialog::get_ps_viewer_parms()       (in fax_list.cpp)     - Prog_config::permitted_clients_list is read by Socket_server::is_valid_peer()       (in socket_server.cpp)   These are protected by the mutex where read by these non-GUI threads, but they   should also be protected by the mutex wherever read by the main (GUI) thread   unless it is known that there can be no concurrency with the execution of these   other threads so far as concerns the reading of these members.  (In fact, as   this program is written this is only an issue with Prog_config::ps_view_cmd,   and locking of it takes place in FileReadSelectDialog::get_view_file_parms() (in   dialogs.cpp), FileListDialog::view_file() and FileListDialog::get_view_file_parms()   (in filelist.cpp) and SocketListDialog::view_file() and   SocketListDialog::get_view_file_parms() (in socket_list.cpp).)4. It would have been convenient to have signal handling in a separate thread   and then to sigwait() on the signals used by this program.  However the main   signal of interest is SIGCHLD, from which the termination of a send or receive   session from efax can be detected, and information about the success or   failure of the sending or receipt of the fax can be obtained and acted on.   However, linuxthreads does not properly implement POSIX threads as regards signal   handling, and with linuxthreads only the thread which fork()s will receive   SIGCHLD.  Thus SIGCHLD cannot be received in a special signal handling thread.   Accordingly, this program adopts the alternative strategy of setting up signal   masks so that only the main (GUI) thread executes the SIGCHLD signal handler,   and it does so asynchronously as if this program were single threaded, and   only the main GUI thread will fork() in order to exec*() efax for sending   or receiving a fax.  This also  means that the asynchronous   efax_controller_childexit_handler() (in efax_controller.cpp) and the synchronous   EfaxController::timer_event() both run in the main GUI thread, as they both   act on the same static volatile sig_atomic_t variables declared in efax_controller.cpp,   and running in the same thread avoids memory synchronisation issues with multi-processor   systems (declaring sigatomic_t variables volatile is not enough to ensure memory   coherency between threads in all multi-processor systems - that will only work with   single processor systems, or multi-processor systems which do not allow write   reordering).  The strategy adopted in this program will therefore work with all   multi-processor systems.*********************************************************************/struct Prog_config {  char* lock_file; // use a char* instead of std::string                   // as we need to use it in a signal handler  std::string fixed_font;  std::string homedir;  char rings;  char receive_dirname[MAX_TEMP_NAME + 1];  bool tone_dial;  bool found_rcfile;  bool GPL_flag;  bool print_popup;  bool sock_server;  bool sock_popup;  bool other_sock_client_address;  bool fax_received_popup;  bool fax_received_exec;  Glib::ustring my_name;  Glib::ustring my_number;  Glib::ustring page_size;  // either 'a4' 'letter' or 'legal'  Glib::ustring page_dim;  Glib::ustring resolution;  Glib::ustring print_cmd;  Glib::ustring print_shrink;  Glib::ustring ps_view_cmd;  Glib::ustring logfile_name;  Glib::ustring sock_server_port;  Glib::ustring fax_received_prog;  std::vector<std::string> parms;  std::vector<std::string> permitted_clients_list;  Glib::RefPtr<Gdk::Pixbuf> window_icon_r;  Glib::Mutex* mutex_p;};extern Prog_config prog_config;           // defined in main.cppGlib::ustring configure_prog(bool reread);// also defined in main.cpp (pass reread as true if                                          // the program parameters are being reread)// generic beep() function defined in main.cppvoid beep(void);// general function for writing an error defined in mainwindow.cpp// the message must not be larger than PIPE_BUF in sizessize_t write_error(const char*);// this function is defined in mainwindow.cpp, and will cause any// message written to stderr to be taken by the in built error pipe// in MainWindow.  Only call this in a child process after fork()ing.int connect_to_stderr(void);#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -