summaryrefslogtreecommitdiff
path: root/libs/notify-wrapper.c
blob: 7ca2e6ad5de43345d736e5060229fd4b07ced6a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

/* notify.defs wrapper code.

   Copyright (C) 2008 Free Software Foundation, Inc.

   Written by FlĂvio Cruz <flaviocruz@gmail.com>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */

#include <mach/boolean.h>
#include <mach/kern_return.h>
#include <mach/message.h>
#include <mach/mig_errors.h>
#include <mach/mig_support.h>

#include <mach/std_types.h>
#include <mach/mach_types.h>
#include <device/device_types.h>
#include <device/net_status.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <hurd/hurd_types.h>

#include <stdio.h>
#include <assert.h>

#include "notify-wrapper.h"

/* this is NULL initialized */
static void *routines[_NUMBER_OF_ROUTINES];

/* function wrappers follows... */

/* do mach notify port deleted */

typedef kern_return_t (*do_mach_notify_port_deleted_type) (mach_port_t,
							   mach_port_t name);

kern_return_t
lisp_do_mach_notify_port_deleted (mach_port_t notify, mach_port_t name)
{
  if (routines[DO_MACH_NOTIFY_PORT_DELETED] == NULL)
    {
      return 0;
    }

  do_mach_notify_port_deleted_type do_mach_notify_port_deleted_routine =
    routines[DO_MACH_NOTIFY_PORT_DELETED];

  return do_mach_notify_port_deleted_routine (notify, name);
}

/* do mach notify msg accepted */

typedef kern_return_t (*do_mach_notify_msg_accepted_type) (mach_port_t,
							   mach_port_t);

kern_return_t
lisp_do_mach_notify_msg_accepted (mach_port_t notify, mach_port_t name)
{
  if (routines[DO_MACH_NOTIFY_MSG_ACCEPTED] == NULL)
    {
      return 0;
    }

  do_mach_notify_msg_accepted_type do_mach_notify_msg_accepted_routine =
    routines[DO_MACH_NOTIFY_MSG_ACCEPTED];

  return do_mach_notify_msg_accepted_routine (notify, name);
}

/* do mach notify port destroyed */

typedef kern_return_t (*do_mach_notify_port_destroyed_type) (mach_port_t,
							     mach_port_t);

kern_return_t
lisp_do_mach_notify_port_destroyed (mach_port_t notify, mach_port_t rights)
{
  if (routines[DO_MACH_NOTIFY_PORT_DESTROYED] == NULL)
    {
      return 0;
    }

  do_mach_notify_port_destroyed_type
    do_mach_port_notify_port_destroyed_routine =
    routines[DO_MACH_NOTIFY_PORT_DESTROYED];

  return do_mach_port_notify_port_destroyed_routine (notify, rights);
}

/* do mach notify no senders */

typedef kern_return_t (*do_mach_notify_no_senders_type) (mach_port_t,
							 mach_port_mscount_t);

kern_return_t
lisp_do_mach_notify_no_senders (mach_port_t notify,
				mach_port_mscount_t mscount)
{
  if (routines[DO_MACH_NOTIFY_NO_SENDERS] == NULL)
    {
      return EOPNOTSUPP;
    }

  do_mach_notify_no_senders_type do_mach_notify_no_senders_routine =
    routines[DO_MACH_NOTIFY_NO_SENDERS];

  return do_mach_notify_no_senders_routine (notify, mscount);
}

/* do mach notify send once */

typedef kern_return_t (*do_mach_notify_send_once_type) (mach_port_t);

kern_return_t
lisp_do_mach_notify_send_once (mach_port_t notify)
{
  if (routines[DO_MACH_NOTIFY_SEND_ONCE] == NULL)
    {
      return 0;
    }

  do_mach_notify_send_once_type do_mach_notify_send_once_routine =
    routines[DO_MACH_NOTIFY_SEND_ONCE];

  return do_mach_notify_send_once_routine (notify);
}

/* do mach notify dead name */

typedef kern_return_t (*do_mach_notify_dead_name_type) (mach_port_t,
							mach_port_t);

kern_return_t
lisp_do_mach_notify_dead_name (mach_port_t notify, mach_port_t name)
{
  if (routines[DO_MACH_NOTIFY_DEAD_NAME] == NULL)
    {
      return EOPNOTSUPP;
    }

  do_mach_notify_dead_name_type do_mach_notify_dead_name_routine =
    routines[DO_MACH_NOTIFY_DEAD_NAME];

  return do_mach_notify_dead_name_routine (notify, name);
}

static const char *
routine_to_str (const NotifyRoutine rot)
{
#define RET(val) case val: return #val ;
  switch (rot)
    {
    RET (DO_MACH_NOTIFY_PORT_DELETED)
    RET (DO_MACH_NOTIFY_MSG_ACCEPTED)
    RET (DO_MACH_NOTIFY_PORT_DESTROYED)
    RET (DO_MACH_NOTIFY_NO_SENDERS)
    RET (DO_MACH_NOTIFY_SEND_ONCE)
    RET (DO_MACH_NOTIFY_DEAD_NAME)
    case _NUMBER_OF_ROUTINES:
    default:
      return "";
    }

#undef RET
}

#include "common.c"

COMMON_FUNCTIONS (notify);