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, 120, 0}; 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[] = { 879 // TODO: find some better defaults... 880 {200, 0, 200}, 881 {0, 200, 200}, 882 {80, 80, 80}, 883 {230, 150, 50}, 884 }; 885 const uint32 kNumColors = sizeof(kColors) / sizeof(kColors[0]); 886 887 fColor = kColors[cpu % kNumColors]; 888 } 889 890 891 // #pragma mark - 892 893 894 CPUCombinedUsageDataSource::CPUCombinedUsageDataSource() 895 : 896 fPreviousActive(0), 897 fPreviousTime(0) 898 { 899 fMinimum = 0; 900 fMaximum = 1000; 901 902 fColor = (rgb_color){200, 200, 0}; 903 } 904 905 906 CPUCombinedUsageDataSource::CPUCombinedUsageDataSource( 907 const CPUCombinedUsageDataSource& other) 908 : DataSource(other) 909 { 910 fPreviousActive = other.fPreviousActive; 911 fPreviousTime = other.fPreviousTime; 912 } 913 914 915 CPUCombinedUsageDataSource::~CPUCombinedUsageDataSource() 916 { 917 } 918 919 920 DataSource* 921 CPUCombinedUsageDataSource::Copy() const 922 { 923 return new CPUCombinedUsageDataSource(*this); 924 } 925 926 927 void 928 CPUCombinedUsageDataSource::Print(BString& text, int64 value) const 929 { 930 char buffer[32]; 931 snprintf(buffer, sizeof(buffer), "%.1f%%", value / 10.0); 932 933 text = buffer; 934 } 935 936 937 int64 938 CPUCombinedUsageDataSource::NextValue(SystemInfo& info) 939 { 940 int32 running = 0; 941 bigtime_t active = 0; 942 943 for (int32 cpu = 0; cpu < info.Info().cpu_count; cpu++) { 944 active += info.Info().cpu_infos[cpu].active_time; 945 running++; 946 // TODO: take disabled CPUs into account 947 } 948 949 int64 percent = int64(1000.0 * (active - fPreviousActive) 950 / (running * (info.Time() - fPreviousTime))); 951 if (percent < 0) 952 percent = 0; 953 if (percent > 1000) 954 percent = 1000; 955 956 fPreviousActive = active; 957 fPreviousTime = info.Time(); 958 959 return percent; 960 } 961 962 963 const char* 964 CPUCombinedUsageDataSource::Label() const 965 { 966 return "CPU Usage"; 967 } 968 969 970 const char* 971 CPUCombinedUsageDataSource::ShortLabel() const 972 { 973 return "CPU"; 974 } 975 976 977 const char* 978 CPUCombinedUsageDataSource::Name() const 979 { 980 return "CPU Usage (combined)"; 981 } 982 983 984 bool 985 CPUCombinedUsageDataSource::MultiCPUOnly() const 986 { 987 return true; 988 } 989 990 991 bool 992 CPUCombinedUsageDataSource::Primary() const 993 { 994 return true; 995 } 996 997 998 // #pragma mark - 999 1000 1001 PageFaultsDataSource::PageFaultsDataSource() 1002 : 1003 fPreviousFaults(0), 1004 fPreviousTime(0) 1005 { 1006 SystemInfo info; 1007 NextValue(info); 1008 1009 fMinimum = 0; 1010 fMaximum = 1000000000LL; 1011 1012 fColor = (rgb_color){200, 0, 150, 0}; 1013 } 1014 1015 1016 PageFaultsDataSource::PageFaultsDataSource(const PageFaultsDataSource& other) 1017 : DataSource(other) 1018 { 1019 fPreviousFaults = other.fPreviousFaults; 1020 fPreviousTime = other.fPreviousTime; 1021 } 1022 1023 1024 PageFaultsDataSource::~PageFaultsDataSource() 1025 { 1026 } 1027 1028 1029 DataSource* 1030 PageFaultsDataSource::Copy() const 1031 { 1032 return new PageFaultsDataSource(*this); 1033 } 1034 1035 1036 void 1037 PageFaultsDataSource::Print(BString& text, int64 value) const 1038 { 1039 char buffer[32]; 1040 snprintf(buffer, sizeof(buffer), "%.1f faults/s", value / 1024.0); 1041 1042 text = buffer; 1043 } 1044 1045 1046 int64 1047 PageFaultsDataSource::NextValue(SystemInfo& info) 1048 { 1049 uint64 faults = info.PageFaults(); 1050 1051 int64 faultsPerSecond = uint64(1024 * double(faults - fPreviousFaults) 1052 / (info.Time() - fPreviousTime) * 1000000.0); 1053 1054 fPreviousFaults = faults; 1055 fPreviousTime = info.Time(); 1056 1057 return faultsPerSecond; 1058 } 1059 1060 1061 const char* 1062 PageFaultsDataSource::Label() const 1063 { 1064 return "Page Faults"; 1065 } 1066 1067 1068 const char* 1069 PageFaultsDataSource::ShortLabel() const 1070 { 1071 return "P-Faults"; 1072 } 1073 1074 1075 const char* 1076 PageFaultsDataSource::Name() const 1077 { 1078 return "Page Faults"; 1079 } 1080 1081 1082 bool 1083 PageFaultsDataSource::AdaptiveScale() const 1084 { 1085 return true; 1086 } 1087 1088 1089 bool 1090 PageFaultsDataSource::Primary() const 1091 { 1092 return false; 1093 } 1094 1095 1096 // #pragma mark - 1097 1098 1099 NetworkUsageDataSource::NetworkUsageDataSource(bool in) 1100 : 1101 fIn(in), 1102 fPreviousBytes(0), 1103 fPreviousTime(0) 1104 { 1105 SystemInfo info; 1106 NextValue(info); 1107 1108 fMinimum = 0; 1109 fMaximum = 1000000000LL; 1110 1111 fColor = fIn ? (rgb_color){200, 150, 0} : (rgb_color){200, 220, 0}; 1112 } 1113 1114 1115 NetworkUsageDataSource::NetworkUsageDataSource( 1116 const NetworkUsageDataSource& other) 1117 : DataSource(other) 1118 { 1119 fIn = other.fIn; 1120 fPreviousBytes = other.fPreviousBytes; 1121 fPreviousTime = other.fPreviousTime; 1122 } 1123 1124 1125 NetworkUsageDataSource::~NetworkUsageDataSource() 1126 { 1127 } 1128 1129 1130 DataSource* 1131 NetworkUsageDataSource::Copy() const 1132 { 1133 return new NetworkUsageDataSource(*this); 1134 } 1135 1136 1137 void 1138 NetworkUsageDataSource::Print(BString& text, int64 value) const 1139 { 1140 char buffer[32]; 1141 snprintf(buffer, sizeof(buffer), "%.1f KB/s", value / 1024.0); 1142 1143 text = buffer; 1144 } 1145 1146 1147 int64 1148 NetworkUsageDataSource::NextValue(SystemInfo& info) 1149 { 1150 uint64 transferred = fIn ? info.NetworkReceived() : info.NetworkSent(); 1151 1152 int64 bytesPerSecond = uint64(double(transferred - fPreviousBytes) 1153 / (info.Time() - fPreviousTime) * 1000000.0); 1154 1155 fPreviousBytes = transferred; 1156 fPreviousTime = info.Time(); 1157 1158 return bytesPerSecond; 1159 } 1160 1161 1162 const char* 1163 NetworkUsageDataSource::Label() const 1164 { 1165 return fIn ? "Receiving" : "Sending"; 1166 } 1167 1168 1169 const char* 1170 NetworkUsageDataSource::ShortLabel() const 1171 { 1172 return fIn ? "RX" : "TX"; 1173 } 1174 1175 1176 const char* 1177 NetworkUsageDataSource::Name() const 1178 { 1179 return fIn ? "Network Receive" : "Network Send"; 1180 } 1181 1182 1183 bool 1184 NetworkUsageDataSource::AdaptiveScale() const 1185 { 1186 return true; 1187 } 1188 1189 1190 scale_type 1191 NetworkUsageDataSource::ScaleType() const 1192 { 1193 return kBytePerSecondScale; 1194 } 1195 1196 1197 bool 1198 NetworkUsageDataSource::Primary() const 1199 { 1200 return true; 1201 } 1202 1203 1204 // #pragma mark - 1205 1206 1207 ClipboardSizeDataSource::ClipboardSizeDataSource(bool text) 1208 { 1209 fMinimum = 0; 1210 fMaximum = UINT32_MAX; 1211 fText = text; 1212 1213 fColor = (rgb_color){0, 150, 255}; 1214 } 1215 1216 1217 ClipboardSizeDataSource::ClipboardSizeDataSource( 1218 const ClipboardSizeDataSource& other) 1219 : DataSource(other) 1220 { 1221 fText = other.fText; 1222 } 1223 1224 1225 ClipboardSizeDataSource::~ClipboardSizeDataSource() 1226 { 1227 } 1228 1229 1230 DataSource* 1231 ClipboardSizeDataSource::Copy() const 1232 { 1233 return new ClipboardSizeDataSource(*this); 1234 } 1235 1236 1237 int64 1238 ClipboardSizeDataSource::NextValue(SystemInfo& info) 1239 { 1240 if (fText) 1241 return info.ClipboardTextSize()/* / 1024*/; 1242 return info.ClipboardSize()/* / 1024*/; 1243 } 1244 1245 1246 const char* 1247 ClipboardSizeDataSource::Label() const 1248 { 1249 return fText ? "Text Clipboard Size" : "Raw Clipboard Size"; 1250 } 1251 1252 1253 const char* 1254 ClipboardSizeDataSource::Unit() const 1255 { 1256 return "bytes"/*"KB"*/; 1257 } 1258 1259 1260 bool 1261 ClipboardSizeDataSource::AdaptiveScale() const 1262 { 1263 return true; 1264 } 1265 1266 1267 // #pragma mark - 1268 1269 1270 MediaNodesDataSource::MediaNodesDataSource() 1271 { 1272 SystemInfo info; 1273 1274 fMinimum = 0; 1275 fMaximum = INT32_MAX; 1276 1277 fColor = (rgb_color){255, 150, 225}; 1278 } 1279 1280 1281 MediaNodesDataSource::~MediaNodesDataSource() 1282 { 1283 } 1284 1285 1286 DataSource* 1287 MediaNodesDataSource::Copy() const 1288 { 1289 return new MediaNodesDataSource(*this); 1290 } 1291 1292 1293 int64 1294 MediaNodesDataSource::NextValue(SystemInfo& info) 1295 { 1296 return info.MediaNodes(); 1297 } 1298 1299 1300 const char* 1301 MediaNodesDataSource::Label() const 1302 { 1303 return "Media Nodes"; 1304 } 1305 1306 1307 bool 1308 MediaNodesDataSource::AdaptiveScale() const 1309 { 1310 return true; 1311 } 1312 1313 1314