ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/prefs_editor_gtk.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/prefs_editor_gtk.cpp (file contents):
Revision 1.32 by gbeauche, 2006-04-16T16:32:45Z vs.
Revision 1.33 by gbeauche, 2006-04-16T21:25:41Z

# Line 39 | Line 39
39   #include "prefs.h"
40   #include "prefs_editor.h"
41  
42 + #define DEBUG 0
43 + #include "debug.h"
44 +
45  
46   // Global variables
47   static GtkWidget *win;                          // Preferences window
# Line 1525 | Line 1528 | static void read_settings(void)
1528  
1529   #ifdef STANDALONE_GUI
1530   #include <errno.h>
1531 + #include <sys/wait.h>
1532 + #include "rpc.h"
1533  
1534   /*
1535   *  Fake unused data and functions
# Line 1533 | Line 1538 | static void read_settings(void)
1538   uint8 XPRAM[XPRAM_SIZE];
1539   void MountVolume(void *fh) { }
1540   void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { }
1536 void WarningAlert(const char *text) { }
1541  
1542  
1543   /*
# Line 1576 | Line 1580 | static void display_alert(int title_id,
1580   *  Display error alert
1581   */
1582  
1583 < static void ErrorAlert(const char *text)
1583 > void ErrorAlert(const char *text)
1584   {
1585          display_alert(STR_ERROR_ALERT_TITLE, STR_GUI_ERROR_PREFIX, STR_QUIT_BUTTON, text);
1586   }
1587  
1588  
1589   /*
1590 + *  Display warning alert
1591 + */
1592 +
1593 + void WarningAlert(const char *text)
1594 + {
1595 +        display_alert(STR_WARNING_ALERT_TITLE, STR_GUI_WARNING_PREFIX, STR_OK_BUTTON, text);
1596 + }
1597 +
1598 +
1599 + /*
1600 + *  RPC handlers
1601 + */
1602 +
1603 + static int handle_ErrorAlert(rpc_connection_t *connection)
1604 + {
1605 +        D(bug("handle_ErrorAlert\n"));
1606 +
1607 +        int error;
1608 +        char *str;
1609 +        if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0)
1610 +                return error;
1611 +
1612 +        ErrorAlert(str);
1613 +        free(str);
1614 +        return RPC_ERROR_NO_ERROR;
1615 + }
1616 +
1617 + static int handle_WarningAlert(rpc_connection_t *connection)
1618 + {
1619 +        D(bug("handle_WarningAlert\n"));
1620 +
1621 +        int error;
1622 +        char *str;
1623 +        if ((error = rpc_method_get_args(connection, RPC_TYPE_STRING, &str, RPC_TYPE_INVALID)) < 0)
1624 +                return error;
1625 +
1626 +        WarningAlert(str);
1627 +        free(str);
1628 +        return RPC_ERROR_NO_ERROR;
1629 + }
1630 +
1631 + static int handle_Exit(rpc_connection_t *connection)
1632 + {
1633 +        D(bug("handle_Exit\n"));
1634 +
1635 +        return RPC_ERROR_NO_ERROR;
1636 + }
1637 +
1638 +
1639 + /*
1640   *  Start standalone GUI
1641   */
1642  
# Line 1610 | Line 1664 | int main(int argc, char *argv[])
1664  
1665          // Transfer control to the executable
1666          if (start) {
1667 <                char b2_path[PATH_MAX];
1668 <                strcpy(b2_path, argv[0]);
1669 <                char *p = strrchr(b2_path, '/');
1670 <                p = p ? p + 1 : b2_path;
1671 <                *p = '\0';
1672 <                strcat(b2_path, "BasiliskII");
1673 <                argv[0] = b2_path;
1674 <                execv(b2_path, argv);
1675 <
1676 <                char str[256];
1677 <                sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(errno));
1678 <                ErrorAlert(str);
1679 <                return 1;
1667 >                char gui_connection_path[64];
1668 >                sprintf(gui_connection_path, "/org/BasiliskII/GUI/%d", getpid());
1669 >                
1670 >                int pid = fork();
1671 >                if (pid == 0) {                 // Child
1672 >                        char b2_path[PATH_MAX];
1673 >                        strcpy(b2_path, argv[0]);
1674 >                        char *p = strrchr(b2_path, '/');
1675 >                        p = p ? p + 1 : b2_path;
1676 >                        *p = '\0';
1677 >                        strcat(b2_path, "BasiliskII");
1678 >                        execl(b2_path, b2_path, "--gui-connection", gui_connection_path, (char *)NULL);
1679 >
1680 >                        char str[256];
1681 >                        sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(errno));
1682 >                        ErrorAlert(str);
1683 >                        return 1;
1684 >                }
1685 >                else {                                  // Parent
1686 >                        rpc_connection_t *connection;
1687 >                        if ((connection = rpc_init_server(gui_connection_path)) == NULL) {
1688 >                        printf("ERROR: failed to initialize GUI-side RPC server connection\n");
1689 >                        return 1;
1690 >                        }
1691 >
1692 >                        static const rpc_method_descriptor_t vtable[] = {
1693 >                                { RPC_METHOD_ERROR_ALERT,                       handle_ErrorAlert },
1694 >                                { RPC_METHOD_WARNING_ALERT,                     handle_WarningAlert },
1695 >                                { RPC_METHOD_EXIT,                                      handle_Exit }
1696 >                        };
1697 >                        if (rpc_method_add_callbacks(connection, vtable, sizeof(vtable) / sizeof(vtable[0])) < 0) {
1698 >                                printf("ERROR: failed to setup GUI method callbacks\n");
1699 >                                return 1;
1700 >                        }
1701 >
1702 >                        if (rpc_listen(connection) < 0) {
1703 >                                printf("ERROR: failed to initialize RPC server thread\n");
1704 >                                return 1;
1705 >                        }
1706 >
1707 >                        int status, ret = -1;
1708 >                        while (waitpid(pid, &status, 0) != pid)
1709 >                                ;
1710 >                        if (WIFEXITED(status))
1711 >                                ret = WEXITSTATUS(status);
1712 >
1713 >                        rpc_exit(connection);
1714 >                        return ret;
1715 >                }
1716          }
1717  
1718          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines