TargetPanel.hh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright (C) 2014 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef TargetPanel_hh
  18. #define TargetPanel_hh
  19. #include "scsi2sd.h"
  20. #include <wx/wx.h>
  21. #include <wx/valnum.h>
  22. #include <wx/checkbox.h>
  23. #include <wx/choice.h>
  24. #include <wx/spinctrl.h>
  25. #include <wx/textctrl.h>
  26. #if __cplusplus >= 201103L
  27. #include <cstdint>
  28. #else
  29. #include <stdint.h>
  30. #endif
  31. #include <utility>
  32. namespace SCSI2SD
  33. {
  34. // A parent class needs to call evaluate on all SCSI targets to sort
  35. // out conflicting SCSI IDs and overlapping memory card use.
  36. // Our custom event is fired whenever a new evaluation is required.
  37. wxDECLARE_EVENT(ConfigChangedEvent, wxCommandEvent);
  38. class TargetPanel : public wxPanel
  39. {
  40. public:
  41. TargetPanel(wxWindow* parent, const TargetConfig& initialConfig);
  42. TargetConfig getConfig() const;
  43. void setConfig(const TargetConfig& config);
  44. bool evaluate(); // Return true if current config is valid.
  45. bool isEnabled() const;
  46. uint8_t getSCSIId() const;
  47. std::pair<uint32_t, uint64_t> getSDSectorRange() const;
  48. // Error messages set by external validation
  49. void setDuplicateID(bool duplicate);
  50. void setSDSectorOverlap(bool overlap);
  51. void setAutoStartSector(uint32_t start);
  52. private:
  53. template<typename EvtType> void onInput(EvtType& event);
  54. void onSizeInput(wxCommandEvent& event);
  55. void evaluateSize();
  56. std::pair<uint32_t, bool> convertUnitsToSectors() const;
  57. void initConfig();
  58. enum
  59. {
  60. ID_enableCtrl = wxID_HIGHEST + 1,
  61. ID_scsiIdCtrl,
  62. ID_deviceTypeCtrl,
  63. ID_parityCtrl,
  64. ID_unitAttCtrl,
  65. ID_startSDSectorCtrl,
  66. ID_autoStartSectorCtrl,
  67. ID_sectorSizeCtrl,
  68. ID_numSectorCtrl,
  69. ID_sizeCtrl,
  70. ID_sizeUnitCtrl,
  71. ID_vendorCtrl,
  72. ID_productCtrl,
  73. ID_revisionCtrl,
  74. ID_serialCtrl
  75. };
  76. enum // Must match the order given to the mySizeUnitCtrl ctor.
  77. {
  78. UNIT_KB,
  79. UNIT_MB,
  80. UNIT_GB
  81. };
  82. wxWindow* myParent;
  83. wxWindow* myChangedEventHandler;
  84. TargetConfig myConfig;
  85. uint32_t myAutoStartSector;
  86. wxCheckBox* myEnableCtrl;
  87. wxSpinCtrl* myScsiIdCtrl;
  88. wxStaticText* myScsiIdMsg;
  89. wxChoice* myDeviceTypeCtrl;
  90. wxCheckBox* myParityCtrl;
  91. wxCheckBox* myUnitAttCtrl;
  92. wxIntegerValidator<uint32_t>* myStartSDSectorValidator;
  93. wxTextCtrl* myStartSDSectorCtrl;
  94. wxCheckBox* myAutoStartSectorCtrl;
  95. wxStaticText* myStartSDSectorMsg;
  96. wxIntegerValidator<uint16_t>* mySectorSizeValidator;
  97. wxTextCtrl* mySectorSizeCtrl;
  98. wxStaticText* mySectorSizeMsg;
  99. wxIntegerValidator<uint32_t>* myNumSectorValidator;
  100. wxTextCtrl* myNumSectorCtrl;
  101. wxStaticText* myNumSectorMsg;
  102. wxFloatingPointValidator<float>* mySizeValidator;
  103. wxTextCtrl* mySizeCtrl;
  104. wxChoice* mySizeUnitCtrl;
  105. wxTextCtrl* myVendorCtrl;
  106. wxStaticText* myVendorMsg;
  107. wxTextCtrl* myProductCtrl;
  108. wxStaticText* myProductMsg;
  109. wxTextCtrl* myRevisionCtrl;
  110. wxStaticText* myRevisionMsg;
  111. wxTextCtrl* mySerialCtrl;
  112. wxStaticText* mySerialMsg;
  113. };
  114. } // namespace SCSI2SD
  115. #endif