diff --git a/code/base/base.h b/code/base/base.h new file mode 100644 index 0000000..36ca77c --- /dev/null +++ b/code/base/base.h @@ -0,0 +1,131 @@ +#pragma once + + +class ref +{ + volatile long ref_; +public: + ref() : ref_(1) + {} + +protected: + virtual ~ref() + {} + +public: + long add_ref(void) + { + return _InterlockedIncrement(&ref_); + } + long release(void) + { + long r = _InterlockedDecrement(&ref_); + + if (r == 0) + delete this; + + return r; + } +}; + +class parameter : public ref +{ +public: + parameter() + {} + +protected: + virtual ~parameter() + {} + +public: + virtual size_t get_size(void) = 0; + virtual void* get_data(void) = 0; // return data pointer, bool*, int*, double*, (wchar_t*) +}; + + +class ui_helper : public ref +{ +public: + ui_helper() + {} +protected: + virtual ~ui_helper() + {} + +public: + enum data_from + { + DATA_FROM_KNOWN = 0, // pre-defined data name, i.e. resulotion, paper, bright, ... + DATA_FROM_USER, // need a window for user inputing + }; + enum value_type + { + VAL_TYPE_BOOL = 0, + VAL_TYPE_INT, + VAL_TYPE_FLOAT, + VAL_TYPE_STRING, + VAL_TYPE_CUSTOM, // custom data, such as gamma table ... + }; + + // get testing parameter ... + virtual parameter* get_user_input(data_from from, value_type type + , const wchar_t* title // window title when from == DATA_FROM_USER, or parameter name when from == DATA_FROM_KNOWN + , const wchar_t* desc = NULL // description of the parameter if from was DATA_FROM_USER, unused in DATA_FROM_KNOWN + ) = 0; + + enum test_event + { + TEST_EVENT_TIPS = 0, // messages in testing process, data is (wchar_t*), flag is unused + TEST_EVENT_xxx, // should be complemented ... + TEST_EVENT_RESULT, // test result, data is (wchar_t*)description, flag is (bool)result, true - test pass + }; + virtual void test_callback(const wchar_t* name/*test name*/, test_event ev, void* data, size_t flag) = 0; + + enum usb_io_type + { + USB_IO_BULK_READ = 0, + USB_IO_BULK_WRITE, + USB_IO_INTERRUPT_READ, + USB_IO_INTERRUPT_WRITE, + }; + virtual int io_bulk_int(usb_io_type type, void* buf, size_t* len/*[in]-size of buf, [out]-data bytes in buf*/); + virtual int io_control(int type, int req, int val, int ind, void* buf, size_t* len/*[in]-in data sizef, [out]-transferred bytes*/); +}; + +#ifdef TEST_DLL +#define DECL_API(ret) __declspec(dllexport) ret __stdcall +#else +#define DECL_API(ret) __declspec(dllimport) ret __stdcall +#endif + +// Function: initialize module +DECL_API(int) func_test_init(void*); + +// Function: to get testing function list supported by this module/DLL +// +// Parameter: buf - to receive the list JSON +// +// len - [in] space of 'buf' in words, [out] words copied in buf, or less buffer size in words if return ERROR_INSUFFICIENT_BUFFER +// +// Return: ERROR_SUCCESS - JSON configuration has copied into buf +// ERROR_INSUFFICIENT_BUFFER - buffer is too small, and the minium size in words is stored in 'len' +// ERROR_INVALID_PARAMETER - NULL for parameter 'len' is not acceptable +DECL_API(int) func_test_get_list(wchar_t* buf // to receive the JSON text + , size_t* len); // [in] space of 'buf' in words, [out] words copied in buf, or less buffer size in words if return ERROR_INSUFFICIENT_BUFFER + +// Function: do ONE function test +// +// Parameter: name - function name +// +// oper - test operation, "start", "pause", "resume", "stop", ... +// +// helper - parameter and testing process callback +// +// Return: error code +DECL_API(int) func_test_go(const wchar_t* name // test name + , const wchar_t* oper // test oper - "start", "pause", "resume", "stop", ... + , ui_helper* helper); + +// Function: uninitialize module +DECL_API(int) func_test_uninit(void*); \ No newline at end of file