1 /*
2  * Copyright (c) 2019-2020 Apple Inc. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __MDNS_BASE_H__
18 #define __MDNS_BASE_H__
19 
20 #include <os/object.h>
21 
22 #if defined(MDNS_OBJECT_FORCE_NO_OBJC) && MDNS_OBJECT_FORCE_NO_OBJC
23 	#define MDNS_OBJECT_USE_OBJC	0
24 #else
25 	#define MDNS_OBJECT_USE_OBJC	OS_OBJECT_USE_OBJC
26 #endif
27 
28 #if MDNS_OBJECT_USE_OBJC
29 	#define MDNS_RETURNS_RETAINED			OS_OBJECT_RETURNS_RETAINED
30 	#define MDNS_DECL(NAME)					OS_OBJECT_DECL_SUBCLASS(mdns_ ## NAME, mdns_object)
31 	#define MDNS_DECL_SUBKIND(NAME, SUPER)	OS_OBJECT_DECL_SUBCLASS(mdns_ ## NAME, mdns_ ## SUPER)
32 	OS_OBJECT_DECL(mdns_object,);
33 #else
34 	#define MDNS_RETURNS_RETAINED
35 	#define MDNS_DECL(NAME)					typedef struct mdns_ ## NAME ## _s *	mdns_ ## NAME ## _t
36 	#define MDNS_DECL_SUBKIND(NAME, SUPER)	MDNS_DECL(NAME)
37 	MDNS_DECL(object);
38 #endif
39 
40 #define MDNS_WARN_RESULT						OS_WARN_RESULT
41 #define MDNS_ASSUME_NONNULL_BEGIN				OS_ASSUME_NONNULL_BEGIN
42 #define MDNS_ASSUME_NONNULL_END					OS_ASSUME_NONNULL_END
43 #define MDNS_PRINTF_FORMAT(FMT_IDX, ARGS_IDX)	__attribute__((__format__ (__printf__, FMT_IDX, ARGS_IDX)))
44 
45 #define MDNS_UNION_MEMBER(NAME)	struct mdns_ ## NAME ## _s *	NAME
46 
47 #define mdns_forget_with_invalidation(X, NAME)	\
48 	do {										\
49 		if (*(X)) {								\
50 			mdns_ ## NAME ## _invalidate(*(X));	\
51 			mdns_release_arc_safe(*(X));		\
52 			*(X) = NULL;						\
53 		}										\
54 	} while (0)
55 
56 #endif	// __MDNS_BASE_H__
57