2 * Copyright 2001-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
7 * Ingo Weinhold, bonefish@@users.sf.net
15 #include <sys/utsname.h>
20 #include <Messenger.h>
23 #include <ServerLink.h>
24 #include <ServerProtocol.h>
30 static team_id sCurrentTeam
= -1;
33 /*! \brief Returns the path to an application's executable.
34 \param team The application's team ID.
35 \param buffer A pointer to a pre-allocated character array of at least
36 size B_PATH_NAME_LENGTH to be filled in by this function.
38 - \c B_OK: Everything went fine.
39 - \c B_BAD_VALUE: \c NULL \a buffer.
43 get_app_path(team_id team
, char *buffer
)
45 // The only way to get the path to the application's executable seems to
46 // be to get an image_info of its image, which also contains a path.
47 // Several images may belong to the team (libraries, add-ons), but only
48 // the one in question should be typed B_APP_IMAGE.
55 while (get_next_image_info(team
, &cookie
, &info
) == B_OK
) {
56 if (info
.type
== B_APP_IMAGE
) {
57 strlcpy(buffer
, info
.name
, B_PATH_NAME_LENGTH
- 1);
62 return B_ENTRY_NOT_FOUND
;
66 /*! \brief Returns the path to the application's executable.
67 \param buffer A pointer to a pre-allocated character array of at least
68 size B_PATH_NAME_LENGTH to be filled in by this function.
70 - \c B_OK: Everything went fine.
71 - \c B_BAD_VALUE: \c NULL \a buffer.
75 get_app_path(char *buffer
)
77 return get_app_path(B_CURRENT_TEAM
, buffer
);
81 /*! \brief Returns an entry_ref referring to an application's executable.
82 \param team The application's team ID.
83 \param ref A pointer to a pre-allocated entry_ref to be initialized
84 to an entry_ref referring to the application's executable.
85 \param traverse If \c true, the function traverses symbolic links.
87 - \c B_OK: Everything went fine.
88 - \c B_BAD_VALUE: \c NULL \a ref.
92 get_app_ref(team_id team
, entry_ref
*ref
, bool traverse
)
94 status_t error
= (ref
? B_OK
: B_BAD_VALUE
);
95 char appFilePath
[B_PATH_NAME_LENGTH
];
98 error
= get_app_path(team
, appFilePath
);
101 BEntry
entry(appFilePath
, traverse
);
102 error
= entry
.GetRef(ref
);
109 /*! \brief Returns an entry_ref referring to the application's executable.
110 \param ref A pointer to a pre-allocated entry_ref to be initialized
111 to an entry_ref referring to the application's executable.
112 \param traverse If \c true, the function traverses symbolic links.
114 - \c B_OK: Everything went fine.
115 - \c B_BAD_VALUE: \c NULL \a ref.
119 get_app_ref(entry_ref
*ref
, bool traverse
)
121 return get_app_ref(B_CURRENT_TEAM
, ref
, traverse
);
125 /*! \brief Returns the ID of the current team.
126 \return The ID of the current team.
131 if (sCurrentTeam
< 0) {
133 if (get_thread_info(find_thread(NULL
), &info
) == B_OK
)
134 sCurrentTeam
= info
.team
;
141 init_team_after_fork()
147 /*! Returns the ID of the supplied team's main thread.
148 \param team The team.
150 - The thread ID of the supplied team's main thread
151 - \c B_BAD_TEAM_ID: The supplied team ID does not identify a running team.
155 main_thread_for(team_id team
)
157 // Under Haiku the team ID is equal to it's main thread ID. We just get
158 // a team info to verify the existence of the team.
160 status_t error
= get_team_info(team
, &info
);
161 return error
== B_OK
? team
: error
;
165 /*! \brief Returns whether the application identified by the supplied
166 \c team_id is currently showing a modal window.
167 \param team the ID of the application in question.
168 \return \c true, if the application is showing a modal window, \c false
172 is_app_showing_modal_window(team_id team
)
179 /*! Creates a connection with the desktop.
182 create_desktop_connection(ServerLink
* link
, const char* name
, int32 capacity
)
184 // Create the port so that the app_server knows where to send messages
185 port_id clientPort
= create_port(capacity
, name
);
189 link
->SetReceiverPort(clientPort
);
191 BMessage
request(AS_GET_DESKTOP
);
192 request
.AddInt32("user", getuid());
193 request
.AddInt32("version", AS_PROTOCOL_VERSION
);
194 request
.AddString("target", getenv("TARGET_SCREEN"));
196 BMessenger
server("application/x-vnd.Haiku-app_server");
198 status_t status
= server
.SendMessage(&request
, &reply
);
202 port_id desktopPort
= reply
.GetInt32("port", B_ERROR
);
206 link
->SetSenderPort(desktopPort
);
211 } // namespace BPrivate