TargetPanel.hh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. std::pair<uint32_t, bool> convertUnitsToSectors() const;
  56. void initConfig();
  57. enum
  58. {
  59. ID_enableCtrl = wxID_HIGHEST + 1,
  60. ID_scsiIdCtrl,
  61. ID_deviceTypeCtrl,
  62. ID_parityCtrl,
  63. ID_unitAttCtrl,
  64. ID_startSDSectorCtrl,
  65. ID_autoStartSectorCtrl,
  66. ID_sectorSizeCtrl,
  67. ID_numSectorCtrl,
  68. ID_sizeCtrl,
  69. ID_sizeUnitCtrl,
  70. ID_vendorCtrl,
  71. ID_productCtrl,
  72. ID_revisionCtrl,
  73. ID_serialCtrl
  74. };
  75. enum // Must match the order given to the mySizeUnitCtrl ctor.
  76. {
  77. UNIT_KB,
  78. UNIT_MB,
  79. UNIT_GB
  80. };
  81. wxWindow* myParent;
  82. wxWindow* myChangedEventHandler;
  83. TargetConfig myConfig;
  84. uint32_t myAutoStartSector;
  85. wxCheckBox* myEnableCtrl;
  86. wxSpinCtrl* myScsiIdCtrl;
  87. wxStaticText* myScsiIdMsg;
  88. wxChoice* myDeviceTypeCtrl;
  89. wxCheckBox* myParityCtrl;
  90. wxCheckBox* myUnitAttCtrl;
  91. wxIntegerValidator<uint32_t>* myStartSDSectorValidator;
  92. wxTextCtrl* myStartSDSectorCtrl;
  93. wxCheckBox* myAutoStartSectorCtrl;
  94. wxStaticText* myStartSDSectorMsg;
  95. wxIntegerValidator<uint16_t>* mySectorSizeValidator;
  96. wxTextCtrl* mySectorSizeCtrl;
  97. wxStaticText* mySectorSizeMsg;
  98. wxIntegerValidator<uint32_t>* myNumSectorValidator;
  99. wxTextCtrl* myNumSectorCtrl;
  100. wxStaticText* myNumSectorMsg;
  101. wxFloatingPointValidator<float>* mySizeValidator;
  102. wxTextCtrl* mySizeCtrl;
  103. wxChoice* mySizeUnitCtrl;
  104. wxTextCtrl* myVendorCtrl;
  105. wxStaticText* myVendorMsg;
  106. wxTextCtrl* myProductCtrl;
  107. wxStaticText* myProductMsg;
  108. wxTextCtrl* myRevisionCtrl;
  109. wxStaticText* myRevisionMsg;
  110. wxTextCtrl* mySerialCtrl;
  111. wxStaticText* mySerialMsg;
  112. };
  113. } // namespace SCSI2SD
  114. #endif