1fbb76349SGreg Clayton //===-- SBPlatform.cpp ------------------------------------------*- C++ -*-===// 2fbb76349SGreg Clayton // 3fbb76349SGreg Clayton // The LLVM Compiler Infrastructure 4fbb76349SGreg Clayton // 5fbb76349SGreg Clayton // This file is distributed under the University of Illinois Open Source 6fbb76349SGreg Clayton // License. See LICENSE.TXT for details. 7fbb76349SGreg Clayton // 8fbb76349SGreg Clayton //===----------------------------------------------------------------------===// 9fbb76349SGreg Clayton 10fbb76349SGreg Clayton #include "lldb/API/SBPlatform.h" 11fbb76349SGreg Clayton #include "lldb/API/SBError.h" 12fbb76349SGreg Clayton #include "lldb/API/SBFileSpec.h" 13fbb76349SGreg Clayton #include "lldb/Core/ArchSpec.h" 14fbb76349SGreg Clayton #include "lldb/Core/Error.h" 15fbb76349SGreg Clayton #include "lldb/Host/File.h" 16fbb76349SGreg Clayton #include "lldb/Interpreter/Args.h" 17fbb76349SGreg Clayton #include "lldb/Target/Target.h" 18fbb76349SGreg Clayton #include "lldb/Target/Platform.h" 19fbb76349SGreg Clayton 20fbb76349SGreg Clayton using namespace lldb; 21fbb76349SGreg Clayton using namespace lldb_private; 22fbb76349SGreg Clayton 23fbb76349SGreg Clayton //---------------------------------------------------------------------- 24fbb76349SGreg Clayton // PlatformConnectOptions 25fbb76349SGreg Clayton //---------------------------------------------------------------------- 26fbb76349SGreg Clayton struct PlatformConnectOptions { 27fbb76349SGreg Clayton PlatformConnectOptions(const char *url = NULL) : 28fbb76349SGreg Clayton m_url(), 29fbb76349SGreg Clayton m_rsync_options(), 30fbb76349SGreg Clayton m_rsync_remote_path_prefix(), 31fbb76349SGreg Clayton m_rsync_enabled(false), 32fbb76349SGreg Clayton m_rsync_omit_hostname_from_remote_path(false), 33fbb76349SGreg Clayton m_local_cache_directory () 34fbb76349SGreg Clayton { 35fbb76349SGreg Clayton if (url && url[0]) 36fbb76349SGreg Clayton m_url = url; 37fbb76349SGreg Clayton } 38fbb76349SGreg Clayton 39fbb76349SGreg Clayton ~PlatformConnectOptions() 40fbb76349SGreg Clayton { 41fbb76349SGreg Clayton } 42fbb76349SGreg Clayton 43fbb76349SGreg Clayton std::string m_url; 44fbb76349SGreg Clayton std::string m_rsync_options; 45fbb76349SGreg Clayton std::string m_rsync_remote_path_prefix; 46fbb76349SGreg Clayton bool m_rsync_enabled; 47fbb76349SGreg Clayton bool m_rsync_omit_hostname_from_remote_path; 48fbb76349SGreg Clayton ConstString m_local_cache_directory; 49fbb76349SGreg Clayton }; 50fbb76349SGreg Clayton 51fbb76349SGreg Clayton //---------------------------------------------------------------------- 52fbb76349SGreg Clayton // PlatformShellCommand 53fbb76349SGreg Clayton //---------------------------------------------------------------------- 54fbb76349SGreg Clayton struct PlatformShellCommand { 55fbb76349SGreg Clayton PlatformShellCommand(const char *shell_command = NULL) : 56fbb76349SGreg Clayton m_command(), 57fbb76349SGreg Clayton m_working_dir(), 58fbb76349SGreg Clayton m_status(0), 59fbb76349SGreg Clayton m_signo(0), 60fbb76349SGreg Clayton m_timeout_sec(UINT32_MAX) 61fbb76349SGreg Clayton { 62fbb76349SGreg Clayton if (shell_command && shell_command[0]) 63fbb76349SGreg Clayton m_command = shell_command; 64fbb76349SGreg Clayton } 65fbb76349SGreg Clayton 66fbb76349SGreg Clayton ~PlatformShellCommand() 67fbb76349SGreg Clayton { 68fbb76349SGreg Clayton } 69fbb76349SGreg Clayton 70fbb76349SGreg Clayton std::string m_command; 71fbb76349SGreg Clayton std::string m_working_dir; 72fbb76349SGreg Clayton std::string m_output; 73fbb76349SGreg Clayton int m_status; 74fbb76349SGreg Clayton int m_signo; 75fbb76349SGreg Clayton uint32_t m_timeout_sec; 76fbb76349SGreg Clayton }; 77fbb76349SGreg Clayton //---------------------------------------------------------------------- 78fbb76349SGreg Clayton // SBPlatformConnectOptions 79fbb76349SGreg Clayton //---------------------------------------------------------------------- 80fbb76349SGreg Clayton SBPlatformConnectOptions::SBPlatformConnectOptions (const char *url) : 81fbb76349SGreg Clayton m_opaque_ptr(new PlatformConnectOptions(url)) 82fbb76349SGreg Clayton { 83fbb76349SGreg Clayton 84fbb76349SGreg Clayton } 85fbb76349SGreg Clayton 86fbb76349SGreg Clayton SBPlatformConnectOptions::SBPlatformConnectOptions(const SBPlatformConnectOptions &rhs) : 87fbb76349SGreg Clayton m_opaque_ptr(new PlatformConnectOptions()) 88fbb76349SGreg Clayton { 89fbb76349SGreg Clayton *m_opaque_ptr = *rhs.m_opaque_ptr; 90fbb76349SGreg Clayton } 91fbb76349SGreg Clayton 92fbb76349SGreg Clayton SBPlatformConnectOptions::~SBPlatformConnectOptions () 93fbb76349SGreg Clayton { 94fbb76349SGreg Clayton delete m_opaque_ptr; 95fbb76349SGreg Clayton } 96fbb76349SGreg Clayton 97fbb76349SGreg Clayton void 98fbb76349SGreg Clayton SBPlatformConnectOptions::operator=(const SBPlatformConnectOptions &rhs) 99fbb76349SGreg Clayton { 100fbb76349SGreg Clayton *m_opaque_ptr = *rhs.m_opaque_ptr; 101fbb76349SGreg Clayton } 102fbb76349SGreg Clayton 103fbb76349SGreg Clayton const char * 104fbb76349SGreg Clayton SBPlatformConnectOptions::GetURL() 105fbb76349SGreg Clayton { 106fbb76349SGreg Clayton if (m_opaque_ptr->m_url.empty()) 107fbb76349SGreg Clayton return NULL; 108fbb76349SGreg Clayton return m_opaque_ptr->m_url.c_str(); 109fbb76349SGreg Clayton } 110fbb76349SGreg Clayton 111fbb76349SGreg Clayton void 112fbb76349SGreg Clayton SBPlatformConnectOptions::SetURL(const char *url) 113fbb76349SGreg Clayton { 114fbb76349SGreg Clayton if (url && url[0]) 115fbb76349SGreg Clayton m_opaque_ptr->m_url = url; 116fbb76349SGreg Clayton else 117fbb76349SGreg Clayton m_opaque_ptr->m_url.clear(); 118fbb76349SGreg Clayton } 119fbb76349SGreg Clayton 120fbb76349SGreg Clayton bool 121fbb76349SGreg Clayton SBPlatformConnectOptions::GetRsyncEnabled() 122fbb76349SGreg Clayton { 123fbb76349SGreg Clayton return m_opaque_ptr->m_rsync_enabled; 124fbb76349SGreg Clayton } 125fbb76349SGreg Clayton 126fbb76349SGreg Clayton void 127fbb76349SGreg Clayton SBPlatformConnectOptions::EnableRsync (const char *options, 128fbb76349SGreg Clayton const char *remote_path_prefix, 129fbb76349SGreg Clayton bool omit_hostname_from_remote_path) 130fbb76349SGreg Clayton { 131fbb76349SGreg Clayton m_opaque_ptr->m_rsync_enabled = true; 132fbb76349SGreg Clayton m_opaque_ptr->m_rsync_omit_hostname_from_remote_path = omit_hostname_from_remote_path; 133fbb76349SGreg Clayton if (remote_path_prefix && remote_path_prefix[0]) 134fbb76349SGreg Clayton m_opaque_ptr->m_rsync_remote_path_prefix = remote_path_prefix; 135fbb76349SGreg Clayton else 136fbb76349SGreg Clayton m_opaque_ptr->m_rsync_remote_path_prefix.clear(); 137fbb76349SGreg Clayton 138fbb76349SGreg Clayton if (options && options[0]) 139fbb76349SGreg Clayton m_opaque_ptr->m_rsync_options = options; 140fbb76349SGreg Clayton else 141fbb76349SGreg Clayton m_opaque_ptr->m_rsync_options.clear(); 142fbb76349SGreg Clayton 143fbb76349SGreg Clayton } 144fbb76349SGreg Clayton 145fbb76349SGreg Clayton void 146fbb76349SGreg Clayton SBPlatformConnectOptions::DisableRsync () 147fbb76349SGreg Clayton { 148fbb76349SGreg Clayton m_opaque_ptr->m_rsync_enabled = false; 149fbb76349SGreg Clayton } 150fbb76349SGreg Clayton 151fbb76349SGreg Clayton const char * 152fbb76349SGreg Clayton SBPlatformConnectOptions::GetLocalCacheDirectory() 153fbb76349SGreg Clayton { 154fbb76349SGreg Clayton return m_opaque_ptr->m_local_cache_directory.GetCString(); 155fbb76349SGreg Clayton } 156fbb76349SGreg Clayton 157fbb76349SGreg Clayton void 158fbb76349SGreg Clayton SBPlatformConnectOptions::SetLocalCacheDirectory(const char *path) 159fbb76349SGreg Clayton { 160fbb76349SGreg Clayton if (path && path[0]) 161fbb76349SGreg Clayton m_opaque_ptr->m_local_cache_directory.SetCString(path); 162fbb76349SGreg Clayton else 163fbb76349SGreg Clayton m_opaque_ptr->m_local_cache_directory = ConstString(); 164fbb76349SGreg Clayton } 165fbb76349SGreg Clayton 166fbb76349SGreg Clayton //---------------------------------------------------------------------- 167fbb76349SGreg Clayton // SBPlatformShellCommand 168fbb76349SGreg Clayton //---------------------------------------------------------------------- 169fbb76349SGreg Clayton SBPlatformShellCommand::SBPlatformShellCommand (const char *shell_command) : 170fbb76349SGreg Clayton m_opaque_ptr(new PlatformShellCommand(shell_command)) 171fbb76349SGreg Clayton { 172fbb76349SGreg Clayton } 173fbb76349SGreg Clayton 174fbb76349SGreg Clayton SBPlatformShellCommand::SBPlatformShellCommand (const SBPlatformShellCommand &rhs) : 175fbb76349SGreg Clayton m_opaque_ptr(new PlatformShellCommand()) 176fbb76349SGreg Clayton { 177fbb76349SGreg Clayton *m_opaque_ptr = *rhs.m_opaque_ptr; 178fbb76349SGreg Clayton } 179fbb76349SGreg Clayton 180fbb76349SGreg Clayton SBPlatformShellCommand::~SBPlatformShellCommand() 181fbb76349SGreg Clayton { 182fbb76349SGreg Clayton delete m_opaque_ptr; 183fbb76349SGreg Clayton } 184fbb76349SGreg Clayton 185fbb76349SGreg Clayton void 186fbb76349SGreg Clayton SBPlatformShellCommand::Clear() 187fbb76349SGreg Clayton { 188fbb76349SGreg Clayton m_opaque_ptr->m_output = std::move(std::string()); 189fbb76349SGreg Clayton m_opaque_ptr->m_status = 0; 190fbb76349SGreg Clayton m_opaque_ptr->m_signo = 0; 191fbb76349SGreg Clayton } 192fbb76349SGreg Clayton 193fbb76349SGreg Clayton const char * 194fbb76349SGreg Clayton SBPlatformShellCommand::GetCommand() 195fbb76349SGreg Clayton { 196fbb76349SGreg Clayton if (m_opaque_ptr->m_command.empty()) 197fbb76349SGreg Clayton return NULL; 198fbb76349SGreg Clayton return m_opaque_ptr->m_command.c_str(); 199fbb76349SGreg Clayton } 200fbb76349SGreg Clayton 201fbb76349SGreg Clayton void 202fbb76349SGreg Clayton SBPlatformShellCommand::SetCommand(const char *shell_command) 203fbb76349SGreg Clayton { 204fbb76349SGreg Clayton if (shell_command && shell_command[0]) 205fbb76349SGreg Clayton m_opaque_ptr->m_command = shell_command; 206fbb76349SGreg Clayton else 207fbb76349SGreg Clayton m_opaque_ptr->m_command.clear(); 208fbb76349SGreg Clayton } 209fbb76349SGreg Clayton 210fbb76349SGreg Clayton const char * 211fbb76349SGreg Clayton SBPlatformShellCommand::GetWorkingDirectory () 212fbb76349SGreg Clayton { 213fbb76349SGreg Clayton if (m_opaque_ptr->m_working_dir.empty()) 214fbb76349SGreg Clayton return NULL; 215fbb76349SGreg Clayton return m_opaque_ptr->m_working_dir.c_str(); 216fbb76349SGreg Clayton } 217fbb76349SGreg Clayton 218fbb76349SGreg Clayton void 219fbb76349SGreg Clayton SBPlatformShellCommand::SetWorkingDirectory (const char *path) 220fbb76349SGreg Clayton { 221fbb76349SGreg Clayton if (path && path[0]) 222fbb76349SGreg Clayton m_opaque_ptr->m_working_dir = path; 223fbb76349SGreg Clayton else 224fbb76349SGreg Clayton m_opaque_ptr->m_working_dir.clear(); 225fbb76349SGreg Clayton } 226fbb76349SGreg Clayton 227fbb76349SGreg Clayton uint32_t 228fbb76349SGreg Clayton SBPlatformShellCommand::GetTimeoutSeconds () 229fbb76349SGreg Clayton { 230fbb76349SGreg Clayton return m_opaque_ptr->m_timeout_sec; 231fbb76349SGreg Clayton } 232fbb76349SGreg Clayton 233fbb76349SGreg Clayton void 234fbb76349SGreg Clayton SBPlatformShellCommand::SetTimeoutSeconds (uint32_t sec) 235fbb76349SGreg Clayton { 236fbb76349SGreg Clayton m_opaque_ptr->m_timeout_sec = sec; 237fbb76349SGreg Clayton } 238fbb76349SGreg Clayton 239fbb76349SGreg Clayton int 240fbb76349SGreg Clayton SBPlatformShellCommand::GetSignal () 241fbb76349SGreg Clayton { 242fbb76349SGreg Clayton return m_opaque_ptr->m_signo; 243fbb76349SGreg Clayton } 244fbb76349SGreg Clayton 245fbb76349SGreg Clayton int 246fbb76349SGreg Clayton SBPlatformShellCommand::GetStatus () 247fbb76349SGreg Clayton { 248fbb76349SGreg Clayton return m_opaque_ptr->m_status; 249fbb76349SGreg Clayton } 250fbb76349SGreg Clayton 251fbb76349SGreg Clayton const char * 252fbb76349SGreg Clayton SBPlatformShellCommand::GetOutput () 253fbb76349SGreg Clayton { 254fbb76349SGreg Clayton if (m_opaque_ptr->m_output.empty()) 255fbb76349SGreg Clayton return NULL; 256fbb76349SGreg Clayton return m_opaque_ptr->m_output.c_str(); 257fbb76349SGreg Clayton } 258fbb76349SGreg Clayton 259fbb76349SGreg Clayton //---------------------------------------------------------------------- 260fbb76349SGreg Clayton // SBPlatform 261fbb76349SGreg Clayton //---------------------------------------------------------------------- 262fbb76349SGreg Clayton SBPlatform::SBPlatform () : 263fbb76349SGreg Clayton m_opaque_sp () 264fbb76349SGreg Clayton { 265fbb76349SGreg Clayton 266fbb76349SGreg Clayton } 267fbb76349SGreg Clayton 268fbb76349SGreg Clayton SBPlatform::SBPlatform (const char *platform_name) : 269fbb76349SGreg Clayton m_opaque_sp () 270fbb76349SGreg Clayton { 271fbb76349SGreg Clayton Error error; 272*615eb7e6SGreg Clayton if (platform_name && platform_name[0]) 273*615eb7e6SGreg Clayton m_opaque_sp = Platform::Create (ConstString(platform_name), error); 274fbb76349SGreg Clayton } 275fbb76349SGreg Clayton 276fbb76349SGreg Clayton SBPlatform::~SBPlatform() 277fbb76349SGreg Clayton { 278fbb76349SGreg Clayton } 279fbb76349SGreg Clayton 280fbb76349SGreg Clayton bool 281fbb76349SGreg Clayton SBPlatform::IsValid () const 282fbb76349SGreg Clayton { 283fbb76349SGreg Clayton return m_opaque_sp.get() != NULL; 284fbb76349SGreg Clayton } 285fbb76349SGreg Clayton 286fbb76349SGreg Clayton void 287fbb76349SGreg Clayton SBPlatform::Clear () 288fbb76349SGreg Clayton { 289fbb76349SGreg Clayton m_opaque_sp.reset(); 290fbb76349SGreg Clayton } 291fbb76349SGreg Clayton 292fbb76349SGreg Clayton const char * 293fbb76349SGreg Clayton SBPlatform::GetName () 294fbb76349SGreg Clayton { 295fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 296fbb76349SGreg Clayton if (platform_sp) 297fbb76349SGreg Clayton return platform_sp->GetName().GetCString(); 298fbb76349SGreg Clayton return NULL; 299fbb76349SGreg Clayton } 300fbb76349SGreg Clayton 301fbb76349SGreg Clayton lldb::PlatformSP 302fbb76349SGreg Clayton SBPlatform::GetSP () const 303fbb76349SGreg Clayton { 304fbb76349SGreg Clayton return m_opaque_sp; 305fbb76349SGreg Clayton } 306fbb76349SGreg Clayton 307fbb76349SGreg Clayton void 308fbb76349SGreg Clayton SBPlatform::SetSP (const lldb::PlatformSP& platform_sp) 309fbb76349SGreg Clayton { 310fbb76349SGreg Clayton m_opaque_sp = platform_sp; 311fbb76349SGreg Clayton } 312fbb76349SGreg Clayton 313fbb76349SGreg Clayton const char * 314fbb76349SGreg Clayton SBPlatform::GetWorkingDirectory() 315fbb76349SGreg Clayton { 316fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 317fbb76349SGreg Clayton if (platform_sp) 318fbb76349SGreg Clayton return platform_sp->GetWorkingDirectory().GetCString(); 319fbb76349SGreg Clayton return NULL; 320fbb76349SGreg Clayton } 321fbb76349SGreg Clayton 322fbb76349SGreg Clayton bool 323fbb76349SGreg Clayton SBPlatform::SetWorkingDirectory(const char *path) 324fbb76349SGreg Clayton { 325fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 326fbb76349SGreg Clayton if (platform_sp) 327fbb76349SGreg Clayton { 328fbb76349SGreg Clayton if (path) 329fbb76349SGreg Clayton platform_sp->SetWorkingDirectory(ConstString(path)); 330fbb76349SGreg Clayton else 331fbb76349SGreg Clayton platform_sp->SetWorkingDirectory(ConstString()); 332fbb76349SGreg Clayton return true; 333fbb76349SGreg Clayton } 334fbb76349SGreg Clayton return false; 335fbb76349SGreg Clayton } 336fbb76349SGreg Clayton 337fbb76349SGreg Clayton SBError 338fbb76349SGreg Clayton SBPlatform::ConnectRemote (SBPlatformConnectOptions &connect_options) 339fbb76349SGreg Clayton { 340fbb76349SGreg Clayton SBError sb_error; 341fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 342fbb76349SGreg Clayton if (platform_sp && connect_options.GetURL()) 343fbb76349SGreg Clayton { 344fbb76349SGreg Clayton Args args; 345fbb76349SGreg Clayton args.AppendArgument(connect_options.GetURL()); 346fbb76349SGreg Clayton sb_error.ref() = platform_sp->ConnectRemote(args); 347fbb76349SGreg Clayton } 348fbb76349SGreg Clayton else 349fbb76349SGreg Clayton { 350fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 351fbb76349SGreg Clayton } 352fbb76349SGreg Clayton return sb_error; 353fbb76349SGreg Clayton } 354fbb76349SGreg Clayton 355fbb76349SGreg Clayton void 356fbb76349SGreg Clayton SBPlatform::DisconnectRemote () 357fbb76349SGreg Clayton { 358fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 359fbb76349SGreg Clayton if (platform_sp) 360fbb76349SGreg Clayton platform_sp->DisconnectRemote(); 361fbb76349SGreg Clayton } 362fbb76349SGreg Clayton 363fbb76349SGreg Clayton bool 364fbb76349SGreg Clayton SBPlatform::IsConnected() 365fbb76349SGreg Clayton { 366fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 367fbb76349SGreg Clayton if (platform_sp) 368fbb76349SGreg Clayton platform_sp->IsConnected(); 369fbb76349SGreg Clayton return false; 370fbb76349SGreg Clayton } 371fbb76349SGreg Clayton 372fbb76349SGreg Clayton const char * 373fbb76349SGreg Clayton SBPlatform::GetTriple() 374fbb76349SGreg Clayton { 375fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 376fbb76349SGreg Clayton if (platform_sp) 377fbb76349SGreg Clayton { 378fbb76349SGreg Clayton ArchSpec arch(platform_sp->GetRemoteSystemArchitecture()); 379fbb76349SGreg Clayton if (arch.IsValid()) 380fbb76349SGreg Clayton { 381fbb76349SGreg Clayton // Const-ify the string so we don't need to worry about the lifetime of the string 382fbb76349SGreg Clayton return ConstString(arch.GetTriple().getTriple().c_str()).GetCString(); 383fbb76349SGreg Clayton } 384fbb76349SGreg Clayton } 385fbb76349SGreg Clayton return NULL; 386fbb76349SGreg Clayton } 387fbb76349SGreg Clayton 388fbb76349SGreg Clayton const char * 389fbb76349SGreg Clayton SBPlatform::GetOSBuild() 390fbb76349SGreg Clayton { 391fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 392fbb76349SGreg Clayton if (platform_sp) 393fbb76349SGreg Clayton { 394fbb76349SGreg Clayton std::string s; 395fbb76349SGreg Clayton if (platform_sp->GetOSBuildString(s)) 396fbb76349SGreg Clayton { 397fbb76349SGreg Clayton if (!s.empty()) 398fbb76349SGreg Clayton { 399fbb76349SGreg Clayton // Const-ify the string so we don't need to worry about the lifetime of the string 400fbb76349SGreg Clayton return ConstString(s.c_str()).GetCString(); 401fbb76349SGreg Clayton } 402fbb76349SGreg Clayton } 403fbb76349SGreg Clayton } 404fbb76349SGreg Clayton return NULL; 405fbb76349SGreg Clayton } 406fbb76349SGreg Clayton 407fbb76349SGreg Clayton const char * 408fbb76349SGreg Clayton SBPlatform::GetOSDescription() 409fbb76349SGreg Clayton { 410fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 411fbb76349SGreg Clayton if (platform_sp) 412fbb76349SGreg Clayton { 413fbb76349SGreg Clayton std::string s; 414fbb76349SGreg Clayton if (platform_sp->GetOSKernelDescription(s)) 415fbb76349SGreg Clayton { 416fbb76349SGreg Clayton if (!s.empty()) 417fbb76349SGreg Clayton { 418fbb76349SGreg Clayton // Const-ify the string so we don't need to worry about the lifetime of the string 419fbb76349SGreg Clayton return ConstString(s.c_str()).GetCString(); 420fbb76349SGreg Clayton } 421fbb76349SGreg Clayton } 422fbb76349SGreg Clayton } 423fbb76349SGreg Clayton return NULL; 424fbb76349SGreg Clayton } 425fbb76349SGreg Clayton 426fbb76349SGreg Clayton const char * 427fbb76349SGreg Clayton SBPlatform::GetHostname () 428fbb76349SGreg Clayton { 429fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 430fbb76349SGreg Clayton if (platform_sp) 431fbb76349SGreg Clayton return platform_sp->GetHostname(); 432fbb76349SGreg Clayton return NULL; 433fbb76349SGreg Clayton } 434fbb76349SGreg Clayton 435fbb76349SGreg Clayton uint32_t 436fbb76349SGreg Clayton SBPlatform::GetOSMajorVersion () 437fbb76349SGreg Clayton { 438fbb76349SGreg Clayton uint32_t major, minor, update; 439fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 440fbb76349SGreg Clayton if (platform_sp && platform_sp->GetOSVersion(major, minor, update)) 441fbb76349SGreg Clayton return major; 442fbb76349SGreg Clayton return UINT32_MAX; 443fbb76349SGreg Clayton 444fbb76349SGreg Clayton } 445fbb76349SGreg Clayton 446fbb76349SGreg Clayton uint32_t 447fbb76349SGreg Clayton SBPlatform::GetOSMinorVersion () 448fbb76349SGreg Clayton { 449fbb76349SGreg Clayton uint32_t major, minor, update; 450fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 451fbb76349SGreg Clayton if (platform_sp && platform_sp->GetOSVersion(major, minor, update)) 452fbb76349SGreg Clayton return minor; 453fbb76349SGreg Clayton return UINT32_MAX; 454fbb76349SGreg Clayton } 455fbb76349SGreg Clayton 456fbb76349SGreg Clayton uint32_t 457fbb76349SGreg Clayton SBPlatform::GetOSUpdateVersion () 458fbb76349SGreg Clayton { 459fbb76349SGreg Clayton uint32_t major, minor, update; 460fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 461fbb76349SGreg Clayton if (platform_sp && platform_sp->GetOSVersion(major, minor, update)) 462fbb76349SGreg Clayton return update; 463fbb76349SGreg Clayton return UINT32_MAX; 464fbb76349SGreg Clayton } 465fbb76349SGreg Clayton 466fbb76349SGreg Clayton SBError 467fbb76349SGreg Clayton SBPlatform::Get (SBFileSpec &src, 468fbb76349SGreg Clayton SBFileSpec &dst) 469fbb76349SGreg Clayton { 470fbb76349SGreg Clayton SBError sb_error; 471fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 472fbb76349SGreg Clayton if (platform_sp) 473fbb76349SGreg Clayton { 474fbb76349SGreg Clayton sb_error.ref() = platform_sp->GetFile(src.ref(), dst.ref()); 475fbb76349SGreg Clayton } 476fbb76349SGreg Clayton else 477fbb76349SGreg Clayton { 478fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 479fbb76349SGreg Clayton } 480fbb76349SGreg Clayton return sb_error; 481fbb76349SGreg Clayton } 482fbb76349SGreg Clayton 483fbb76349SGreg Clayton SBError 484fbb76349SGreg Clayton SBPlatform::Put (SBFileSpec &src, 485fbb76349SGreg Clayton SBFileSpec &dst) 486fbb76349SGreg Clayton { 487fbb76349SGreg Clayton SBError sb_error; 488fbb76349SGreg Clayton 489fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 490fbb76349SGreg Clayton if (platform_sp) 491fbb76349SGreg Clayton { 492fbb76349SGreg Clayton if (src.Exists()) 493fbb76349SGreg Clayton { 494fbb76349SGreg Clayton uint32_t permissions = src.ref().GetPermissions(); 495fbb76349SGreg Clayton if (permissions == 0) 496fbb76349SGreg Clayton { 497fbb76349SGreg Clayton if (src.ref().GetFileType() == FileSpec::eFileTypeDirectory) 498fbb76349SGreg Clayton permissions = eFilePermissionsDirectoryDefault; 499fbb76349SGreg Clayton else 500fbb76349SGreg Clayton permissions = eFilePermissionsFileDefault; 501fbb76349SGreg Clayton } 502fbb76349SGreg Clayton 503fbb76349SGreg Clayton sb_error.ref() = platform_sp->PutFile(src.ref(), 504fbb76349SGreg Clayton dst.ref(), 505fbb76349SGreg Clayton permissions); 506fbb76349SGreg Clayton } 507fbb76349SGreg Clayton else 508fbb76349SGreg Clayton { 509fbb76349SGreg Clayton sb_error.ref().SetErrorStringWithFormat("'src' argument doesn't exist: '%s'", src.ref().GetPath().c_str()); 510fbb76349SGreg Clayton } 511fbb76349SGreg Clayton } 512fbb76349SGreg Clayton else 513fbb76349SGreg Clayton { 514fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 515fbb76349SGreg Clayton } 516fbb76349SGreg Clayton return sb_error; 517fbb76349SGreg Clayton } 518fbb76349SGreg Clayton 519fbb76349SGreg Clayton SBError 520fbb76349SGreg Clayton SBPlatform::Install (SBFileSpec &src, 521fbb76349SGreg Clayton SBFileSpec &dst) 522fbb76349SGreg Clayton { 523fbb76349SGreg Clayton SBError sb_error; 524fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 525fbb76349SGreg Clayton if (platform_sp) 526fbb76349SGreg Clayton { 527fbb76349SGreg Clayton if (src.Exists()) 528fbb76349SGreg Clayton { 529fbb76349SGreg Clayton sb_error.ref() = platform_sp->Install(src.ref(), dst.ref()); 530fbb76349SGreg Clayton } 531fbb76349SGreg Clayton else 532fbb76349SGreg Clayton { 533fbb76349SGreg Clayton sb_error.ref().SetErrorStringWithFormat("'src' argument doesn't exist: '%s'", src.ref().GetPath().c_str()); 534fbb76349SGreg Clayton } 535fbb76349SGreg Clayton } 536fbb76349SGreg Clayton else 537fbb76349SGreg Clayton { 538fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 539fbb76349SGreg Clayton } 540fbb76349SGreg Clayton return sb_error; 541fbb76349SGreg Clayton } 542fbb76349SGreg Clayton 543fbb76349SGreg Clayton 544fbb76349SGreg Clayton SBError 545fbb76349SGreg Clayton SBPlatform::Run (SBPlatformShellCommand &shell_command) 546fbb76349SGreg Clayton { 547fbb76349SGreg Clayton SBError sb_error; 548fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 549fbb76349SGreg Clayton if (platform_sp) 550fbb76349SGreg Clayton { 551fbb76349SGreg Clayton if (platform_sp->IsConnected()) 552fbb76349SGreg Clayton { 553fbb76349SGreg Clayton const char *command = shell_command.GetCommand(); 554fbb76349SGreg Clayton if (command) 555fbb76349SGreg Clayton { 556fbb76349SGreg Clayton const char *working_dir = shell_command.GetWorkingDirectory(); 557fbb76349SGreg Clayton if (working_dir == NULL) 558fbb76349SGreg Clayton { 559fbb76349SGreg Clayton working_dir = platform_sp->GetWorkingDirectory().GetCString(); 560fbb76349SGreg Clayton if (working_dir) 561fbb76349SGreg Clayton shell_command.SetWorkingDirectory(working_dir); 562fbb76349SGreg Clayton } 563fbb76349SGreg Clayton sb_error.ref() = platform_sp->RunShellCommand(command, 564fbb76349SGreg Clayton working_dir, 565fbb76349SGreg Clayton &shell_command.m_opaque_ptr->m_status, 566fbb76349SGreg Clayton &shell_command.m_opaque_ptr->m_signo, 567fbb76349SGreg Clayton &shell_command.m_opaque_ptr->m_output, 568fbb76349SGreg Clayton shell_command.m_opaque_ptr->m_timeout_sec); 569fbb76349SGreg Clayton } 570fbb76349SGreg Clayton else 571fbb76349SGreg Clayton { 572fbb76349SGreg Clayton sb_error.SetErrorString("invalid shell command (empty)"); 573fbb76349SGreg Clayton } 574fbb76349SGreg Clayton } 575fbb76349SGreg Clayton else 576fbb76349SGreg Clayton { 577fbb76349SGreg Clayton sb_error.SetErrorString("not connected"); 578fbb76349SGreg Clayton } 579fbb76349SGreg Clayton } 580fbb76349SGreg Clayton else 581fbb76349SGreg Clayton { 582fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 583fbb76349SGreg Clayton } 584fbb76349SGreg Clayton return sb_error; 585fbb76349SGreg Clayton } 586fbb76349SGreg Clayton 587fbb76349SGreg Clayton SBError 588fbb76349SGreg Clayton SBPlatform::MakeDirectory (const char *path, uint32_t file_permissions) 589fbb76349SGreg Clayton { 590fbb76349SGreg Clayton SBError sb_error; 591fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 592fbb76349SGreg Clayton if (platform_sp) 593fbb76349SGreg Clayton { 594fbb76349SGreg Clayton sb_error.ref() = platform_sp->MakeDirectory(path, file_permissions); 595fbb76349SGreg Clayton } 596fbb76349SGreg Clayton else 597fbb76349SGreg Clayton { 598fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 599fbb76349SGreg Clayton } 600fbb76349SGreg Clayton return sb_error; 601fbb76349SGreg Clayton } 602fbb76349SGreg Clayton 603fbb76349SGreg Clayton uint32_t 604fbb76349SGreg Clayton SBPlatform::GetFilePermissions (const char *path) 605fbb76349SGreg Clayton { 606fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 607fbb76349SGreg Clayton if (platform_sp) 608fbb76349SGreg Clayton { 609fbb76349SGreg Clayton uint32_t file_permissions = 0; 610fbb76349SGreg Clayton platform_sp->GetFilePermissions(path, file_permissions); 611fbb76349SGreg Clayton return file_permissions; 612fbb76349SGreg Clayton } 613fbb76349SGreg Clayton return 0; 614fbb76349SGreg Clayton 615fbb76349SGreg Clayton } 616fbb76349SGreg Clayton 617fbb76349SGreg Clayton SBError 618fbb76349SGreg Clayton SBPlatform::SetFilePermissions (const char *path, uint32_t file_permissions) 619fbb76349SGreg Clayton { 620fbb76349SGreg Clayton SBError sb_error; 621fbb76349SGreg Clayton PlatformSP platform_sp(GetSP()); 622fbb76349SGreg Clayton if (platform_sp) 623fbb76349SGreg Clayton { 624fbb76349SGreg Clayton sb_error.ref() = platform_sp->SetFilePermissions(path, file_permissions); 625fbb76349SGreg Clayton } 626fbb76349SGreg Clayton else 627fbb76349SGreg Clayton { 628fbb76349SGreg Clayton sb_error.SetErrorString("invalid platform"); 629fbb76349SGreg Clayton } 630fbb76349SGreg Clayton return sb_error; 631fbb76349SGreg Clayton 632fbb76349SGreg Clayton } 633fbb76349SGreg Clayton 634