~ubuntu-branches/ubuntu/lucid/jack-audio-connection-kit/lucid

« back to all changes in this revision

Viewing changes to config/os/macosx/ipc.h

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-12-06 11:05:15 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081206110515-xa9v9pajr9jqvfvg
Tags: 0.115.6-1ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  - Redirect stderr in bash completion (Debian #504488).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright � Grame 2003
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
    
 
18
    Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
 
19
    grame@rd.grame.fr
 
20
*/
 
21
 
 
22
#ifndef __ipc__
 
23
#define __ipc__
 
24
 
 
25
#include <mach/mach_error.h>
 
26
#include <servers/bootstrap.h>
 
27
#include <jack/internal.h>
 
28
#include <jack/engine.h>
 
29
#include <libjack/local.h>              /* JOQ: fix me */
 
30
 
 
31
/*
 
32
    RPC without time out can put the jack server in a blocked state
 
33
    (waiting for the client answer) when a client is killed.  The
 
34
    mach_msg function does not return any error in this case. Using
 
35
    time out solve the problem but does not seems really satisfactory.
 
36
*/
 
37
 
 
38
#define WAIT 2500 /* in millisecond */
 
39
 
 
40
static inline int 
 
41
jack_client_resume(jack_client_internal_t *client)
 
42
{
 
43
        mach_msg_header_t *head =  &client->message.header;
 
44
        int err;
 
45
        
 
46
        if (!client->running) {
 
47
            err = mach_msg (head, MACH_RCV_MSG, 0, sizeof(client->message),
 
48
                            client->serverport, 0, MACH_PORT_NULL);
 
49
            if (err) {
 
50
                jack_error("jack_client_resume: priming receive error: %s\n", 
 
51
                           mach_error_string(err));
 
52
                return -1;
 
53
            }
 
54
            client->running = TRUE;
 
55
        }else {
 
56
            /* remote port is already the send-once he sent us */
 
57
            head->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0);
 
58
            head->msgh_local_port = MACH_PORT_NULL;
 
59
            head->msgh_size = sizeof(mach_msg_header_t);
 
60
    
 
61
            err = mach_msg(head, (MACH_SEND_MSG|MACH_RCV_MSG|
 
62
                                  MACH_SEND_TIMEOUT|MACH_RCV_TIMEOUT), 
 
63
                           sizeof(*head), sizeof(client->message),
 
64
                           client->serverport, WAIT, MACH_PORT_NULL);
 
65
                
 
66
            if (err) {
 
67
            
 
68
                    /*
 
69
                    switch(err) {
 
70
                        case MACH_SEND_TIMED_OUT:
 
71
                                 jack_error("MACH_SEND_TIMED_OUT %s\n",
 
72
                                            client->control->name);
 
73
                                 break;
 
74
                                 
 
75
                           case MACH_RCV_TIMED_OUT:
 
76
                                 jack_error("MACH_RCV_TIMED_OUT %s\n",
 
77
                                            client->control->name);
 
78
                                 break;
 
79
                     
 
80
                         case MACH_SEND_INVALID_DEST:
 
81
                                 jack_error("MACH_SEND_INVALID_DEST %s\n",
 
82
                                            client->control->name);
 
83
                                 break;
 
84
                    }
 
85
                    */
 
86
                    
 
87
                    jack_error("jack_client_resume: send error for %s\n",
 
88
                               mach_error_string(err));
 
89
                    return err;
 
90
            }
 
91
        }
 
92
        
 
93
        return 0;
 
94
}
 
95
 
 
96
static inline int 
 
97
jack_client_suspend(jack_client_t * client)
 
98
{
 
99
        int err = 0;
 
100
        mach_msg_header_t * head = &client->message.header;
 
101
     
 
102
        head->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND,
 
103
                                         MACH_MSG_TYPE_MAKE_SEND_ONCE);
 
104
        head->msgh_remote_port = client->serverport;
 
105
        head->msgh_local_port = client->replyport;
 
106
        head->msgh_size = sizeof(mach_msg_header_t);
 
107
     
 
108
        err = mach_msg(head, MACH_SEND_MSG|MACH_RCV_MSG|MACH_SEND_TIMEOUT, 
 
109
                       sizeof(mach_msg_header_t), sizeof(client->message),
 
110
                       client->replyport, WAIT, MACH_PORT_NULL);
 
111
            
 
112
        if (err) {
 
113
            jack_error("jack_client_suspend: RPC error: %s\n",
 
114
                       mach_error_string(err));
 
115
            return -1;
 
116
        }
 
117
        
 
118
        return 0;
 
119
}
 
120
 
 
121
static inline void 
 
122
allocate_mach_serverport(jack_engine_t * engine, jack_client_internal_t *client)
 
123
{
 
124
        char buf[256];
 
125
        snprintf(buf, 256, "JackMachPort_%d", engine->portnum); 
 
126
        
 
127
        if (mach_port_allocate(engine->servertask, MACH_PORT_RIGHT_RECEIVE,
 
128
                               &client->serverport)){
 
129
            jack_error("allocate_mach_serverport: can't allocate mach port");
 
130
        }
 
131
        
 
132
        if (mach_port_insert_right(engine->servertask, client->serverport,
 
133
                                   client->serverport, MACH_MSG_TYPE_MAKE_SEND)){
 
134
            jack_error("allocate_mach_serverport: error inserting mach rights");
 
135
        }
 
136
        
 
137
        if (bootstrap_register(engine->bp, buf, client->serverport)){
 
138
            jack_error("allocate_mach_serverport: can't check in mach port");
 
139
        }
 
140
        
 
141
        client->portnum = engine->portnum;
 
142
        engine->portnum++;
 
143
}
 
144
 
 
145
static inline int 
 
146
allocate_mach_clientport(jack_client_t * client, int portnum)
 
147
{
 
148
        char buf[256];
 
149
        snprintf(buf, 256, "JackMachPort_%d", portnum); 
 
150
        
 
151
        if (bootstrap_look_up(client->bp, buf, &client->serverport)){
 
152
            jack_error ("allocate_mach_clientport: can't find mach server port");
 
153
            return -1;
 
154
        }
 
155
        
 
156
        if (mach_port_allocate(client->clienttask, MACH_PORT_RIGHT_RECEIVE,
 
157
                               &client->replyport)){
 
158
            jack_error("allocate_mach_clientport: can't allocate mach port");
 
159
            return -1;
 
160
        }
 
161
        
 
162
        return 0;
 
163
}
 
164
 
 
165
#endif /* __ipc__ */