HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MBSDUtil.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_MBSDUtil.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * These functions replace the SGI forms with BSD forms.
11  *
12  */
13 
14 #ifndef __UT_MBSDUtil_h__
15 #define __UT_MBSDUtil_h__
16 
17 #include "UT_API.h"
18 
19 // Everything after this point will only be included if on MacOS.
20 
21 #if defined(MBSD)
22 
23 #include <sched.h>
24 #include <signal.h>
25 #include <fcntl.h>
26 #include <time.h>
27 #include <math.h>
28 #include <errno.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/time.h>
32 #include <SYS/SYS_Types.h>
33 
34 #include "UT_Assert.h"
35 #include "UT_StringMap.h"
36 #include "UT_UniquePtr.h"
37 #include "UT_WorkBuffer.h"
38 
39 //
40 // Defines:
41 //
42 #define PR_SADDR 1
43 #define MP_NPROCS 0
44 #ifndef SO_REUSEPORT
45 #define SO_REUSEPORT SO_REUSEADDR
46 #endif
47 #ifndef SIGCLD
48 #define SIGCLD SIGCHLD
49 #endif
50 
51 
52 #define CONF_INITUSERS 1
53 
54 #define FNONBLK FNONBLOCK
55 
56 #define sigset(a,b) signal(a,b)
57 #define sighold(a)
58 #define sigrelse(a)
59 #define sigignore(a)
60 #define oserror() errno
61 
62 #ifndef CLK_TCK
63 #define CLK_TCK CLOCKS_PER_SEC
64 #endif
65 
66 #define sginap(a) UTnap(a*10)
67 
68 // Forward declares
69 class UT_WorkArgs;
70 class UT_ExtensionList;
71 
72 //
73 // Functions:
74 //
75 UT_API long UTnap(long ms);
76 
77 UT_API void cftime (char *dest, char *fmt, time_t *now);
78 
79 UT_API pid_t sproc (void (*)(void *), unsigned int flags = 0, void *args = 0);
80 
81 UT_API int sysmp (int val, ...);
82 
83 UT_API int usconfig (int flag, int data);
84 
85 UT_API extern void UTclearHostnameCache();
86 UT_API extern int UTgethostname(char *host, int len);
87 
88 UT_API void MBSDregisterThread();
89 
90 UT_API int MBSDLaunchApp(UT_WorkArgs& args);
91 
92 UT_API void MBSDLoadURL(const char* url);
93 
94 UT_API void MBSDLoadDirectory(const char* directory,
95  const char* selected_file = nullptr);
96 
97 UT_API std::string MBSDurlToLocalPathStdString(const std::string &url);
98 
99 UT_API void MBSDAddImageAndMovieExtensions(UT_ExtensionList & extension_list);
100 
101 UT_API UT_AssertResponse MBSDgetAssertResponse(UT_WorkBuffer &info);
102 
103 UT_API void MBSDalert(const char *msg, const char *details);
104 
105 UT_API float MBSDgetBackingScaleFactor(int screen_idx);
106 
107 UT_API bool UTisUserAnAdmin();
108 
109 /// This class works around a bug in OSX Yosemite where duplicate environment
110 /// variable entries can exist in the global `environ`. Duplicate entries cause
111 /// spawned bash/sh subprocesses to inherit the wrong variable values if the
112 /// parent process was launched from launchd. This bug is logged with Apple as
113 /// bug 18724538 and submitted by rvinluan@sidefx.com. When that bug is fixed,
114 /// then we can get rid of UT_MBSDEnvironFix.
115 ///
116 /// This class works around the bug by recreating `environ` without duplicate
117 /// entries.
118 ///
119 /// To use this class, create an instance of it before spawning a process.
120 /// For example:
121 /// {
122 /// #if defined(MBSD)
123 /// UT_MBSDEnvironFix tmp_env;
124 /// #endif
125 /// ::execlp("/bin/bsh", "sh", "-c", command, NULL);
126 /// }
127 class UT_API UT_MBSDEnvironFix
128 {
129 public:
130  UT_MBSDEnvironFix();
131  ~UT_MBSDEnvironFix();
132 private:
133  char **myOrigEnviron;
134  UT_UniquePtr<char*[]> myFixedEnviron;
135  UT_StringMap<UT_String> myEnvironMap;
136 };
137 
138 #ifdef __OBJC__
139 
140 #import <Foundation/Foundation.h>
141 
142 class UT_String;
143 
144 UT_API NSString * MBSDconvertString(const UT_String & ut_string);
145 UT_API UT_String MBSDconvertString(NSString * string);
146 
147 NSString * UTstackTraceForException(NSException * exception);
148 
149 #endif
150 
151 #endif // MBSD
152 
153 #endif // __UT_MBSDUtil_h__
GLbitfield flags
Definition: glcorearb.h:1596
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
UT_AssertResponse
Definition: UT_Assert.h:213
#define UT_API
Definition: UT_API.h:14
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_API int UTgethostname(UT_String &host)
GLuint GLfloat * val
Definition: glcorearb.h:1608
**If you just want to fire and args
Definition: thread.h:609
Definition: format.h:895