1 /* 2 * Copyright 2008-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "DataSource.h" 8 9 #include <stdio.h> 10 #include <stdint.h> 11 12 #include <OS.h> 13 #include <String.h> 14 15 #include "SystemInfo.h" 16 17 18 const DataSource* kSources[] = { 19 new UsedMemoryDataSource(), 20 new CachedMemoryDataSource(), 21 new SwapSpaceDataSource(), 22 new PageFaultsDataSource(), 23 new CPUUsageDataSource(), 24 new CPUCombinedUsageDataSource(), 25 new NetworkUsageDataSource(true), 26 new NetworkUsageDataSource(false), 27 new BlockCacheDataSource(), 28 new SemaphoresDataSource(), 29 new PortsDataSource(), 30 new ThreadsDataSource(), 31 new TeamsDataSource(), 32 new RunningAppsDataSource(), 33 new ClipboardSizeDataSource(false), 34 new ClipboardSizeDataSource(true), 35 new MediaNodesDataSource() 36 }; 37 const size_t kSourcesCount = sizeof(kSources) / sizeof(kSources[0]); 38 39 40 DataSource::DataSource(int64 initialMin, int64 initialMax) 41 : 42 fMinimum(initialMin), 43 fMaximum(initialMax), 44 fInterval(1000000LL), 45 fColor((rgb_color){200, 0, 0}) 46 { 47 } 48 49 50 DataSource::DataSource() 51 : 52 fMinimum(0), 53 fMaximum(100), 54 fInterval(1000000LL), 55 fColor((rgb_color){200, 0, 0}) 56 { 57 } 58 59 60 DataSource::DataSource(const DataSource& other) 61 { 62 fMinimum = other.fMinimum; 63 fMaximum = other.fMaximum; 64 fInterval = other.fInterval; 65 fColor = other.fColor; 66 } 67 68 69 DataSource::~DataSource() 70 { 71 } 72 73 74 DataSource* 75 DataSource::Copy() const 76 { 77 return NULL; 78 // this class cannot be copied 79 } 80 81 82 DataSource* 83 DataSource::CopyForCPU(int32 cpu) const 84 { 85 return Copy(); 86 } 87 88 89 int64 90 DataSource::Minimum() const 91 { 92 return fMinimum; 93 } 94 95 96 int64 97 DataSource::Maximum() const 98 { 99 return fMaximum; 100 } 101 102 103 bigtime_t 104 DataSource::RefreshInterval() const 105 { 106 return fInterval; 107 } 108 109 110 void 111 DataSource::SetLimits(int64 min, int64 max) 112 { 113 fMinimum = min; 114 fMaximum = max; 115 } 116 117 118 void 119 DataSource::SetRefreshInterval(bigtime_t interval) 120 { 121 fInterval = interval; 122 } 123 124 125 void 126 DataSource::SetColor(rgb_color color) 127 { 128 fColor = color; 129 } 130 131 132 int64 133 DataSource::NextValue(SystemInfo& info) 134 { 135 return 0; 136 } 137 138 139 void 140 DataSource::Print(BString& text, int64 value) const 141 { 142 text = ""; 143 text << value; 144 } 145 146 147 const char* 148 DataSource::Name() const 149 { 150 return Label(); 151 } 152 153 154 const char* 155 DataSource::ShortLabel() const 156 { 157 return Label(); 158 } 159 160 161 const char* 162 DataSource::Label() const 163 { 164 return ""; 165 } 166 167 168 const char* 169 DataSource::Unit() const 170 { 171 return ""; 172 } 173 174 175 rgb_color 176 DataSource::Color() const 177 { 178 return fColor; 179 } 180 181 182 bool 183 DataSource::AdaptiveScale() const 184 { 185 return false; 186 } 187 188 189 scale_type 190 DataSource::ScaleType() const 191 { 192 return kNoScale; 193 } 194 195 196 int32 197 DataSource::CPU() const 198 { 199 return 0; 200 } 201 202 203 bool 204 DataSource::PerCPU() const 205 { 206 return false; 207 } 208 209 210 bool 211 DataSource::MultiCPUOnly() const 212 { 213 return false; 214 } 215 216 217 bool 218 DataSource::Primary() const 219 { 220 return false; 221 } 222 223 224 /*static*/ int32 225 DataSource::CountSources() 226 { 227 return kSourcesCount; 228 } 229 230 231 /*static*/ const DataSource* 232 DataSource::SourceAt(int32 index) 233 { 234 if (index >= (int32)kSourcesCount || index < 0) 235 return NULL; 236 237 return kSources[index]; 238 } 239 240 241 /*static*/ const DataSource* 242 DataSource::FindSource(const char* name) 243 { 244 for (uint32 i = 0; i < kSourcesCount; i++) { 245 const DataSource* source = kSources[i]; 246 if (!strcmp(source->Name(), name)) 247 return source; 248 } 249 250 return NULL; 251 } 252 253 254 /*static*/ int32 255 DataSource::IndexOf(const DataSource* source) 256 { 257 const char* name = source->Name(); 258 259 for (uint32 i = 0; i < kSourcesCount; i++) { 260 if (!strcmp(kSources[i]->Name(), name)) 261 return i; 262 } 263 264 return -1; 265 } 266 267 268 // #pragma mark - 269 270 271 MemoryDataSource::MemoryDataSource() 272 { 273 SystemInfo info; 274 275 fMinimum = 0; 276 fMaximum = info.MaxMemory(); 277 } 278 279 280 MemoryDataSource::~MemoryDataSource() 281 { 282 } 283 284 285 void 286 MemoryDataSource::Print(BString& text, int64 value) const 287 { 288 char buffer[32]; 289 snprintf(buffer, sizeof(buffer), "%.1f MB", value / 1048576.0); 290 291 text = buffer; 292 } 293 294 295 const char* 296 MemoryDataSource::Unit() const 297 { 298 return "MB"; 299 } 300 301 302 // #pragma mark - 303 304 305 UsedMemoryDataSource::UsedMemoryDataSource() 306 { 307 } 308 309 310 UsedMemoryDataSource::~UsedMemoryDataSource() 311 { 312 } 313 314 315 DataSource* 316 UsedMemoryDataSource::Copy() const 317 { 318 return new UsedMemoryDataSource(*this); 319 } 320 321 322 int64 323 UsedMemoryDataSource::NextValue(SystemInfo& info) 324 { 325 return info.UsedMemory(); 326 } 327 328 329 const char* 330 UsedMemoryDataSource::Label() const 331 { 332 return "Used memory"; 333 } 334 335 336 const char* 337 UsedMemoryDataSource::ShortLabel() const 338 { 339 return "Memory"; 340 } 341 342 343 bool 344 UsedMemoryDataSource::Primary() const 345 { 346 return true; 347 } 348 349 350 // #pragma mark - 351 352 353 CachedMemoryDataSource::CachedMemoryDataSource() 354 { 355 fColor = (rgb_color){0, 200, 0}; 356 } 357 358 359 CachedMemoryDataSource::~CachedMemoryDataSource() 360 { 361 } 362 363 364 DataSource* 365 CachedMemoryDataSource::Copy() const 366 { 367 return new CachedMemoryDataSource(*this); 368 } 369 370 371 int64 372 CachedMemoryDataSource::NextValue(SystemInfo& info) 373 { 374 return info.CachedMemory(); 375 } 376 377 378 const char* 379 CachedMemoryDataSource::Label() const 380 { 381 return "Cached memory"; 382 } 383 384 385 const char* 386 CachedMemoryDataSource::ShortLabel() const 387 { 388 return "Cache"; 389 } 390 391 392 bool 393 CachedMemoryDataSource::Primary() const 394 { 395 return true; 396 } 397 398 399 // #pragma mark - 400 401 402 SwapSpaceDataSource::SwapSpaceDataSource() 403 { 404 SystemInfo info; 405 406 fColor = (rgb_color){0, 120, 0}; 407 fMaximum = info.MaxSwapSpace(); 408 } 409 410 411 SwapSpaceDataSource::~SwapSpaceDataSource() 412 { 413 } 414 415 416 DataSource* 417 SwapSpaceDataSource::Copy() const 418 { 419 return new SwapSpaceDataSource(*this); 420 } 421 422 423 int64 424 SwapSpaceDataSource::NextValue(SystemInfo& info) 425 { 426 return info.UsedSwapSpace(); 427 } 428 429 430 const char* 431 SwapSpaceDataSource::Label() const 432 { 433 return "Swap space"; 434 } 435 436 437 const char* 438 SwapSpaceDataSource::ShortLabel() const 439 { 440 return "Swap"; 441 } 442 443 444 bool 445 SwapSpaceDataSource::Primary() const 446 { 447 return true; 448 } 449 450 451 // #pragma mark - 452 453 454 BlockCacheDataSource::BlockCacheDataSource() 455 { 456 fColor = (rgb_color){0, 0, 120}; 457 } 458 459 460 BlockCacheDataSource::~BlockCacheDataSource() 461 { 462 } 463 464 465 DataSource* 466 BlockCacheDataSource::Copy() const 467 { 468 return new BlockCacheDataSource(*this); 469 } 470 471 472 int64 473 BlockCacheDataSource::NextValue(SystemInfo& info) 474 { 475 system_memory_info memoryInfo; 476 status_t status = get_system_info_etc(B_MEMORY_INFO, &memoryInfo, 477 sizeof(system_memory_info)); 478 if (status != B_OK) 479 return 0; 480 481 return memoryInfo.block_cache_memory; 482 } 483 484 485 const char* 486 BlockCacheDataSource::Label() const 487 { 488 return "Block cache memory"; 489 } 490 491 492 const char* 493 BlockCacheDataSource::ShortLabel() const 494 { 495 return "Block cache"; 496 } 497 498 499 // #pragma mark - 500 501 502 SemaphoresDataSource::SemaphoresDataSource() 503 { 504 SystemInfo info; 505 506 fMinimum = 0; 507 fMaximum = info.MaxSemaphores(); 508 509 fColor = (rgb_color){100, 200, 100}; 510 } 511 512 513 SemaphoresDataSource::~SemaphoresDataSource() 514 { 515 } 516 517 518 DataSource* 519 SemaphoresDataSource::Copy() const 520 { 521 return new SemaphoresDataSource(*this); 522 } 523 524 525 int64 526 SemaphoresDataSource::NextValue(SystemInfo& info) 527 { 528 return info.UsedSemaphores(); 529 } 530 531 532 const char* 533 SemaphoresDataSource::Label() const 534 { 535 return "Semaphores"; 536 } 537 538 539 const char* 540 SemaphoresDataSource::ShortLabel() const 541 { 542 return "Sems"; 543 } 544 545 546 bool 547 SemaphoresDataSource::AdaptiveScale() const 548 { 549 return true; 550 } 551 552 553 // #pragma mark - 554 555 556 PortsDataSource::PortsDataSource() 557 { 558 SystemInfo info; 559 560 fMinimum = 0; 561 fMaximum = info.MaxPorts(); 562 563 fColor = (rgb_color){180, 200, 180}; 564 } 565 566 567 PortsDataSource::~PortsDataSource() 568 { 569 } 570 571 572 DataSource* 573 PortsDataSource::Copy() const 574 { 575 return new PortsDataSource(*this); 576 } 577 578 579 int64 580 PortsDataSource::NextValue(SystemInfo& info) 581 { 582 return info.UsedPorts(); 583 } 584 585 586 const char* 587 PortsDataSource::Label() const 588 { 589 return "Ports"; 590 } 591 592 593 bool 594 PortsDataSource::AdaptiveScale() const 595 { 596 return true; 597 } 598 599 600 // #pragma mark - 601 602 603 ThreadsDataSource::ThreadsDataSource() 604 { 605 SystemInfo info; 606 607 fMinimum = 0; 608 fMaximum = info.MaxThreads(); 609 610 fColor = (rgb_color){0, 0, 200}; 611 } 612 613 614 ThreadsDataSource::~ThreadsDataSource() 615 { 616 } 617 618 619 DataSource* 620 ThreadsDataSource::Copy() const 621 { 622 return new ThreadsDataSource(*this); 623 } 624 625 626 int64 627 ThreadsDataSource::NextValue(SystemInfo& info) 628 { 629 return info.UsedThreads(); 630 } 631 632 633 const char* 634 ThreadsDataSource::Label() const 635 { 636 return "Threads"; 637 } 638 639 640 bool 641 ThreadsDataSource::AdaptiveScale() const 642 { 643 return true; 644 } 645 646 647 // #pragma mark - 648 649 650 TeamsDataSource::TeamsDataSource() 651 { 652 SystemInfo info; 653 654 fMinimum = 0; 655 fMaximum = info.MaxTeams(); 656 657 fColor = (rgb_color){0, 150, 255}; 658 } 659 660 661 TeamsDataSource::~TeamsDataSource() 662 { 663 } 664 665 666 DataSource* 667 TeamsDataSource::Copy() const 668 { 669 return new TeamsDataSource(*this); 670 } 671 672 673 int64 674 TeamsDataSource::NextValue(SystemInfo& info) 675 { 676 return info.UsedTeams(); 677 } 678 679 680 const char* 681 TeamsDataSource::Label() const 682 { 683 return "Teams"; 684 } 685 686 687 bool 688 TeamsDataSource::AdaptiveScale() const 689 { 690 return true; 691 } 692 693 694 // #pragma mark - 695 696 697 RunningAppsDataSource::RunningAppsDataSource() 698 { 699 SystemInfo info; 700 701 fMinimum = 0; 702 fMaximum = info.MaxRunningApps(); 703 704 fColor = (rgb_color){100, 150, 255}; 705 } 706 707 708 RunningAppsDataSource::~RunningAppsDataSource() 709 { 710 } 711 712 713 DataSource* 714 RunningAppsDataSource::Copy() const 715 { 716 return new RunningAppsDataSource(*this); 717 } 718 719 720 int64 721 RunningAppsDataSource::NextValue(SystemInfo& info) 722 { 723 return info.UsedRunningApps(); 724 } 725 726 727 const char* 728 RunningAppsDataSource::Label() const 729 { 730 return "Running applications"; 731 } 732 733 734 const char* 735 RunningAppsDataSource::ShortLabel() const 736 { 737 return "Apps"; 738 } 739 740 741 bool 742 RunningAppsDataSource::AdaptiveScale() const 743 { 744 return true; 745 } 746 747 748 // #pragma mark - 749 750 751 CPUUsageDataSource::CPUUsageDataSource(int32 cpu) 752 : 753 fPreviousActive(0), 754 fPreviousTime(0) 755 { 756 fMinimum = 0; 757 fMaximum = 1000; 758 759 _SetCPU(cpu); 760 } 761 762 763 CPUUsageDataSource::CPUUsageDataSource(const CPUUsageDataSource& other) 764 : DataSource(other) 765 { 766 fPreviousActive = other.fPreviousActive; 767 fPreviousTime = other.fPreviousTime; 768 fCPU = other.fCPU; 769 fLabel = other.fLabel; 770 fShortLabel = other.fShortLabel; 771 } 772 773 774 CPUUsageDataSource::~CPUUsageDataSource() 775 { 776 } 777 778 779 DataSource* 780 CPUUsageDataSource::Copy() const 781 { 782 return new CPUUsageDataSource(*this); 783 } 784 785 786 DataSource* 787 CPUUsageDataSource::CopyForCPU(int32 cpu) const 788 { 789 CPUUsageDataSource* copy = new CPUUsageDataSource(*this); 790 copy->_SetCPU(cpu); 791 792 return copy; 793 } 794 795 796 void 797 CPUUsageDataSource::Print(BString& text, int64 value) const 798 { 799 char buffer[32]; 800 snprintf(buffer, sizeof(buffer), "%.1f%%", value / 10.0); 801 802 text = buffer; 803 } 804 805 806 int64 807 CPUUsageDataSource::NextValue(SystemInfo& info) 808 { 809 bigtime_t active = info.Info().cpu_infos[fCPU].active_time; 810 811 int64 percent = int64(1000.0 * (active - fPreviousActive) 812 / (info.Time() - fPreviousTime)); 813 if (percent < 0) 814 percent = 0; 815 if (percent > 1000) 816 percent = 1000; 817 818 fPreviousActive = active; 819 fPreviousTime = info.Time(); 820 821 return percent; 822 } 823 824 825 const char* 826 CPUUsageDataSource::Label() const 827 { 828 return fLabel.String(); 829 } 830 831 832 const char* 833 CPUUsageDataSource::ShortLabel() const 834 { 835 return fShortLabel.String(); 836 } 837 838 839 const char* 840 CPUUsageDataSource::Name() const 841 { 842 return "CPU usage"; 843 } 844 845 846 int32 847 CPUUsageDataSource::CPU() const 848 { 849 return fCPU; 850 } 851 852 853 bool 854 CPUUsageDataSource::PerCPU() const 855 { 856 return true; 857 } 858 859 860 bool 861 CPUUsageDataSource::Primary() const 862 { 863 return true; 864 } 865 866 867 void 868 CPUUsageDataSource::_SetCPU(int32 cpu) 869 { 870 fCPU = cpu; 871 fLabel = "CPU"; 872 if (SystemInfo().CPUCount() > 1) 873 fLabel << " " << cpu; 874 875 fShortLabel = fLabel; 876 fLabel << " usage"; 877 878 const rgb_color kColors[B_MAX_CPU_COUNT] = { 879 // TODO: find some better defaults... 880 {200, 0, 200}, 881 {0, 200, 200}, 882 {80, 80, 80}, 883 {230, 150, 50}, 884 {255, 0, 0}, 885 {0, 255, 0}, 886 {0, 0, 255}, 887 {0, 150, 230} 888 }; 889 const uint32 kNumColors = sizeof(kColors) / sizeof(kColors[0]); 890 891 fColor = kColors[cpu % kNumColors]; 892 } 893 894 895 // #pragma mark - 896 897 898 CPUCombinedUsageDataSource::CPUCombinedUsageDataSource() 899 : 900 fPreviousActive(0), 901 fPreviousTime(0) 902 { 903 fMinimum = 0; 904 fMaximum = 1000; 905 906 fColor = (rgb_color){200, 200, 0}; 907 } 908 909 910 CPUCombinedUsageDataSource::CPUCombinedUsageDataSource( 911 const CPUCombinedUsageDataSource& other) 912 : DataSource(other) 913 { 914 fPreviousActive = other.fPreviousActive; 915 fPreviousTime = other.fPreviousTime; 916 } 917 918 919 CPUCombinedUsageDataSource::~CPUCombinedUsageDataSource() 920 { 921 } 922 923 924 DataSource* 925 CPUCombinedUsageDataSource::Copy() const 926 { 927 return new CPUCombinedUsageDataSource(*this); 928 } 929 930 931 void 932 CPUCombinedUsageDataSource::Print(BString& text, int64 value) const 933 { 934 char buffer[32]; 935 snprintf(buffer, sizeof(buffer), "%.1f%%", value / 10.0); 936 937 text = buffer; 938 } 939 940 941 int64 942 CPUCombinedUsageDataSource::NextValue(SystemInfo& info) 943 { 944 int32 running = 0; 945 bigtime_t active = 0; 946 947 for (int32 cpu = 0; cpu < info.Info().cpu_count; cpu++) { 948 active += info.Info().cpu_infos[cpu].active_time; 949 running++; 950 // TODO: take disabled CPUs into account 951 } 952 953 int64 percent = int64(1000.0 * (active - fPreviousActive) 954 / (running * (info.Time() - fPreviousTime))); 955 if (percent < 0) 956 percent = 0; 957 if (percent > 1000) 958 percent = 1000; 959 960 fPreviousActive = active; 961 fPreviousTime = info.Time(); 962 963 return percent; 964 } 965 966 967 const char* 968 CPUCombinedUsageDataSource::Label() const 969 { 970 return "CPU usage"; 971 } 972 973 974 const char* 975 CPUCombinedUsageDataSource::ShortLabel() const 976 { 977 return "CPU"; 978 } 979 980 981 const char* 982 CPUCombinedUsageDataSource::Name() const 983 { 984 return "CPU usage (combined)"; 985 } 986 987 988 bool 989 CPUCombinedUsageDataSource::MultiCPUOnly() const 990 { 991 return true; 992 } 993 994 995 bool 996 CPUCombinedUsageDataSource::Primary() const 997 { 998 return true; 999 } 1000 1001 1002 // #pragma mark - 1003 1004 1005 PageFaultsDataSource::PageFaultsDataSource() 1006 : 1007 fPreviousFaults(0), 1008 fPreviousTime(0) 1009 { 1010 SystemInfo info; 1011 NextValue(info); 1012 1013 fMinimum = 0; 1014 fMaximum = 1000000000LL; 1015 1016 fColor = (rgb_color){200, 0, 150, 0}; 1017 } 1018 1019 1020 PageFaultsDataSource::PageFaultsDataSource(const PageFaultsDataSource& other) 1021 : DataSource(other) 1022 { 1023 fPreviousFaults = other.fPreviousFaults; 1024 fPreviousTime = other.fPreviousTime; 1025 } 1026 1027 1028 PageFaultsDataSource::~PageFaultsDataSource() 1029 { 1030 } 1031 1032 1033 DataSource* 1034 PageFaultsDataSource::Copy() const 1035 { 1036 return new PageFaultsDataSource(*this); 1037 } 1038 1039 1040 void 1041 PageFaultsDataSource::Print(BString& text, int64 value) const 1042 { 1043 char buffer[32]; 1044 snprintf(buffer, sizeof(buffer), "%.1f faults/s", value / 1024.0); 1045 1046 text = buffer; 1047 } 1048 1049 1050 int64 1051 PageFaultsDataSource::NextValue(SystemInfo& info) 1052 { 1053 uint64 faults = info.PageFaults(); 1054 1055 int64 faultsPerSecond = uint64(1024 * double(faults - fPreviousFaults) 1056 / (info.Time() - fPreviousTime) * 1000000.0); 1057 1058 fPreviousFaults = faults; 1059 fPreviousTime = info.Time(); 1060 1061 return faultsPerSecond; 1062 } 1063 1064 1065 const char* 1066 PageFaultsDataSource::Label() const 1067 { 1068 return "Page faults"; 1069 } 1070 1071 1072 const char* 1073 PageFaultsDataSource::ShortLabel() const 1074 { 1075 return "P-faults"; 1076 } 1077 1078 1079 const char* 1080 PageFaultsDataSource::Name() const 1081 { 1082 return "Page faults"; 1083 } 1084 1085 1086 bool 1087 PageFaultsDataSource::AdaptiveScale() const 1088 { 1089 return true; 1090 } 1091 1092 1093 bool 1094 PageFaultsDataSource::Primary() const 1095 { 1096 return false; 1097 } 1098 1099 1100 // #pragma mark - 1101 1102 1103 NetworkUsageDataSource::NetworkUsageDataSource(bool in) 1104 : 1105 fIn(in), 1106 fPreviousBytes(0), 1107 fPreviousTime(0) 1108 { 1109 SystemInfo info; 1110 NextValue(info); 1111 1112 fMinimum = 0; 1113 fMaximum = 1000000000LL; 1114 1115 fColor = fIn ? (rgb_color){200, 150, 0} : (rgb_color){200, 220, 0}; 1116 } 1117 1118 1119 NetworkUsageDataSource::NetworkUsageDataSource( 1120 const NetworkUsageDataSource& other) 1121 : DataSource(other) 1122 { 1123 fIn = other.fIn; 1124 fPreviousBytes = other.fPreviousBytes; 1125 fPreviousTime = other.fPreviousTime; 1126 } 1127 1128 1129 NetworkUsageDataSource::~NetworkUsageDataSource() 1130 { 1131 } 1132 1133 1134 DataSource* 1135 NetworkUsageDataSource::Copy() const 1136 { 1137 return new NetworkUsageDataSource(*this); 1138 } 1139 1140 1141 void 1142 NetworkUsageDataSource::Print(BString& text, int64 value) const 1143 { 1144 char buffer[32]; 1145 snprintf(buffer, sizeof(buffer), "%.1f KB/s", value / 1024.0); 1146 1147 text = buffer; 1148 } 1149 1150 1151 int64 1152 NetworkUsageDataSource::NextValue(SystemInfo& info) 1153 { 1154 uint64 transferred = fIn ? info.NetworkReceived() : info.NetworkSent(); 1155 1156 int64 bytesPerSecond = uint64(double(transferred - fPreviousBytes) 1157 / (info.Time() - fPreviousTime) * 1000000.0); 1158 1159 fPreviousBytes = transferred; 1160 fPreviousTime = info.Time(); 1161 1162 return bytesPerSecond; 1163 } 1164 1165 1166 const char* 1167 NetworkUsageDataSource::Label() const 1168 { 1169 return fIn ? "Receiving" : "Sending"; 1170 } 1171 1172 1173 const char* 1174 NetworkUsageDataSource::ShortLabel() const 1175 { 1176 return fIn ? "RX" : "TX"; 1177 } 1178 1179 1180 const char* 1181 NetworkUsageDataSource::Name() const 1182 { 1183 return fIn ? "Network receive" : "Network send"; 1184 } 1185 1186 1187 bool 1188 NetworkUsageDataSource::AdaptiveScale() const 1189 { 1190 return true; 1191 } 1192 1193 1194 scale_type 1195 NetworkUsageDataSource::ScaleType() const 1196 { 1197 return kBytePerSecondScale; 1198 } 1199 1200 1201 bool 1202 NetworkUsageDataSource::Primary() const 1203 { 1204 return true; 1205 } 1206 1207 1208 // #pragma mark - 1209 1210 1211 ClipboardSizeDataSource::ClipboardSizeDataSource(bool text) 1212 { 1213 fMinimum = 0; 1214 fMaximum = UINT32_MAX; 1215 fText = text; 1216 1217 fColor = (rgb_color){0, 150, 255}; 1218 } 1219 1220 1221 ClipboardSizeDataSource::ClipboardSizeDataSource( 1222 const ClipboardSizeDataSource& other) 1223 : DataSource(other) 1224 { 1225 fText = other.fText; 1226 } 1227 1228 1229 ClipboardSizeDataSource::~ClipboardSizeDataSource() 1230 { 1231 } 1232 1233 1234 DataSource* 1235 ClipboardSizeDataSource::Copy() const 1236 { 1237 return new ClipboardSizeDataSource(*this); 1238 } 1239 1240 1241 int64 1242 ClipboardSizeDataSource::NextValue(SystemInfo& info) 1243 { 1244 if (fText) 1245 return info.ClipboardTextSize()/* / 1024*/; 1246 return info.ClipboardSize()/* / 1024*/; 1247 } 1248 1249 1250 const char* 1251 ClipboardSizeDataSource::Label() const 1252 { 1253 return fText ? "Text clipboard size" : "Raw clipboard size"; 1254 } 1255 1256 1257 const char* 1258 ClipboardSizeDataSource::Unit() const 1259 { 1260 return "bytes"/*"KB"*/; 1261 } 1262 1263 1264 bool 1265 ClipboardSizeDataSource::AdaptiveScale() const 1266 { 1267 return true; 1268 } 1269 1270 1271 // #pragma mark - 1272 1273 1274 MediaNodesDataSource::MediaNodesDataSource() 1275 { 1276 SystemInfo info; 1277 1278 fMinimum = 0; 1279 fMaximum = INT32_MAX; 1280 1281 fColor = (rgb_color){255, 150, 225}; 1282 } 1283 1284 1285 MediaNodesDataSource::~MediaNodesDataSource() 1286 { 1287 } 1288 1289 1290 DataSource* 1291 MediaNodesDataSource::Copy() const 1292 { 1293 return new MediaNodesDataSource(*this); 1294 } 1295 1296 1297 int64 1298 MediaNodesDataSource::NextValue(SystemInfo& info) 1299 { 1300 return info.MediaNodes(); 1301 } 1302 1303 1304 const char* 1305 MediaNodesDataSource::Label() const 1306 { 1307 return "Media nodes"; 1308 } 1309 1310 1311 bool 1312 MediaNodesDataSource::AdaptiveScale() const 1313 { 1314 return true; 1315 } 1316 1317 1318