00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <new>
00029 #include <string.h>
00030
00031 #include <List.h>
00032 #include <Roster.h>
00033
00034 #include <RemoteRoster.h>
00035
00036 #include "Debug.h"
00037 #include "RemoteRosterImpl.h"
00038 #include "RMessageServerDefs.h"
00039
00050 00060 _EXPORT
00061 RemoteRoster::RemoteRoster(const BNetAddress* address)
00062 : fInitStatus(B_NO_INIT),
00063 fAddress(NULL),
00064 fImpl(NULL)
00065 {
00066 if (address)
00067 SetTo(address);
00068 }
00069
00070 00080 _EXPORT
00081 RemoteRoster::RemoteRoster(const char* host)
00082 : fInitStatus(B_NO_INIT),
00083 fAddress(NULL),
00084 fImpl(NULL)
00085 {
00086 if (host)
00087 SetTo(host);
00088 }
00089
00090 00093 _EXPORT
00094 RemoteRoster::~RemoteRoster()
00095 {
00096 Unset();
00097 }
00098
00099 00108 _EXPORT
00109 status_t
00110 RemoteRoster::SetTo(const BNetAddress* address)
00111 {
00112 FUNCTION_START();
00113 Unset();
00114 if (!address)
00115 return (fInitStatus = B_BAD_VALUE);
00116
00117 status_t error = B_OK;
00118 fAddress = new(nothrow) BNetAddress(*address);
00119 if (!fAddress)
00120 RETURN_ERROR(B_NO_MEMORY);
00121
00122 BMessenger serverMessenger(kRMessageServerSignature);
00123 if (error == B_OK && !serverMessenger.IsValid())
00124 SET_ERROR(error, B_ERROR);
00125
00126 if (error == B_OK) {
00127
00128 BMessage request(MSG_CONNECT);
00129 BMessage addressArchive;
00130 error = fAddress->Archive(&addressArchive);
00131 if (error == B_OK)
00132 SET_ERROR(error, request.AddMessage("address", &addressArchive));
00133
00134 BMessage reply;
00135 if (error == B_OK)
00136 SET_ERROR(error, serverMessenger.SendMessage(&request, &reply));
00137
00138 if (error == B_OK && reply.what != MSG_REPLY)
00139 SET_ERROR(error, B_ERROR);
00140 status_t requestError;
00141 if (error == B_OK && reply.FindInt32("error", &requestError) == B_OK)
00142 SET_ERROR(error, requestError);
00143
00144 BMessenger requestMessenger;
00145 if (error == B_OK) {
00146 SET_ERROR(error, reply.FindMessenger("request messenger",
00147 &requestMessenger));
00148 }
00149 if (error == B_OK && !requestMessenger.IsValid())
00150 SET_ERROR(error, B_ERROR);
00151
00152 if (error == B_OK) {
00153 fImpl = new(nothrow) RemoteRosterImpl(requestMessenger);
00154 if (fImpl) {
00155 SET_ERROR(error, fImpl->InitCheck());
00156 } else {
00157 SET_ERROR(error, B_NO_MEMORY);
00158 }
00159 }
00160 }
00161
00162 if (error != B_OK)
00163 Unset();
00164 RETURN_ERROR(fInitStatus = error);
00165 }
00166
00167 00176 _EXPORT
00177 status_t
00178 RemoteRoster::SetTo(const char* host)
00179 {
00180 Unset();
00181 if (!host)
00182 return (fInitStatus = B_BAD_VALUE);
00183 BNetAddress address(host);
00184 if (address.InitCheck() != B_OK)
00185 RETURN_ERROR(fInitStatus = address.InitCheck());
00186 return SetTo(&address);
00187 }
00188
00189 00192 _EXPORT
00193 void
00194 RemoteRoster::Unset()
00195 {
00196 delete fAddress;
00197 fAddress = NULL;
00198 delete fImpl;
00199 fImpl = NULL;
00200 fInitStatus = B_NO_INIT;
00201 }
00202
00203 00211 _EXPORT
00212 status_t
00213 RemoteRoster::InitCheck() const
00214 {
00215 return fInitStatus;
00216 }
00217
00218 00231 _EXPORT
00232 status_t
00233 RemoteRoster::GetAppList(BList* teams) const
00234 {
00235 return (InitCheck() == B_OK ? fImpl->GetAppList(teams) : InitCheck());
00236 }
00237
00238 00255 _EXPORT
00256 status_t
00257 RemoteRoster::GetAppList(const char* signature, BList* teams) const
00258 {
00259 return (InitCheck() == B_OK ? fImpl->GetAppList(signature, teams)
00260 : InitCheck());
00261 }
00262
00263 00280 _EXPORT
00281 team_id
00282 RemoteRoster::TeamFor(const char* signature) const
00283 {
00284 return (InitCheck() == B_OK ? fImpl->TeamFor(signature) : InitCheck());
00285 }
00286
00287 00306 _EXPORT
00307 status_t
00308 RemoteRoster::GetRunningAppInfo(const char* signature, app_info* info) const
00309 {
00310 return (InitCheck() == B_OK ? fImpl->GetRunningAppInfo(signature, info)
00311 : InitCheck());
00312 }
00313
00314 00329 _EXPORT
00330 status_t
00331 RemoteRoster::GetRunningAppInfo(team_id team, app_info* info) const
00332 {
00333 return (InitCheck() == B_OK ? fImpl->GetRunningAppInfo(team, info)
00334 : InitCheck());
00335 }
00336
00337 00349 _EXPORT
00350 status_t
00351 RemoteRoster::GetActiveAppInfo(app_info* info) const
00352 {
00353 return (InitCheck() == B_OK ? fImpl->GetActiveAppInfo(info) : InitCheck());
00354 }
00355
00356 00373 _EXPORT
00374 status_t
00375 RemoteRoster::GetMessenger(const char* signature, BMessenger* messenger,
00376 bool byName) const
00377 {
00378 return (InitCheck() == B_OK
00379 ? fImpl->GetMessenger(signature, messenger, byName) : InitCheck());
00380 }
00381
00382 00395 _EXPORT
00396 status_t
00397 RemoteRoster::GetMessenger(team_id team, BMessenger* messenger) const
00398 {
00399 return (InitCheck() == B_OK ? fImpl->GetMessenger(team, messenger)
00400 : InitCheck());
00401 }