Batch 28 commit a7fca39 gave ESP event loop accounting as MEDIUM: 2 of 3 attempts passed and the failure was a wrong fix in a complete session. The task comes from the commit Qwen measured, its digest matches, and it is still present at the batch branch head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 lines
55 KiB
JSON
2 lines
55 KiB
JSON
{"LICENSE": "\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n", "Makefile": "CC = gcc\nCFLAGS = -std=gnu11 -O0 -g -Iplatform -Icomponents/esp_event/include -Icomponents/esp_event/private_include\n.PHONY: smoke clean\nsmoke: build/smoke\n\t./build/smoke\nbuild/smoke: components/esp_event/esp_event.c components/esp_event/private_include/esp_event_internal.h platform/os.c smoke.c\n\tmkdir -p build\n\t$(CC) $(CFLAGS) components/esp_event/esp_event.c platform/os.c smoke.c -o $@\nclean:\n\trm -f build/smoke\n", "smoke.c": "/* Local normal-path demonstration. SPDX-License-Identifier: Apache-2.0 */\n#include \"esp_event.h\"\n#include <stdio.h>\nstatic unsigned calls;\nstatic void on_event(void *arg,esp_event_base_t base,int32_t id,void *data){\n unsigned *value=data;(void)arg;printf(\"event %s %d value=%u\\n\",base,(int)id,value?*value:0);calls++;\n}\nint main(void){\n esp_event_loop_handle_t loop;esp_event_loop_args_t args={.queue_size=4,.task_name=NULL};unsigned value=42;\n if(esp_event_loop_create(&args,&loop)!=ESP_OK)return 1;\n if(esp_event_handler_register_with(loop,ESP_EVENT_ANY_BASE,ESP_EVENT_ANY_ID,on_event,NULL)!=ESP_OK)return 2;\n if(esp_event_post_to(loop,\"SAMPLE\",1,&value,sizeof(value),0)!=ESP_OK)return 3;\n if(esp_event_loop_run(loop,50)!=ESP_OK || calls!=1)return 4;\n esp_event_dump(stdout);return esp_event_loop_delete(loop)!=ESP_OK;\n}\n", "README.md": "# Event diagnostics workbench\n\nThis workbench builds the generic ESP event-loop implementation on an application-thread software adapter. Run `make smoke` with GCC and Make. The smoke program exercises one normal event.\n\nThe complete public behavior used by this application is in `docs/event-contract.md`; the original API comments remain in `components/esp_event/include/`. All clauses in that contract are delivery requirements.\n\nOnly these files are collected for grading:\n\n- `components/esp_event/esp_event.c`\n- `components/esp_event/private_include/esp_event_internal.h`\n\nThe upstream source and headers retain their original contents. The local `platform/` files supply byte queues, mutexes, logical task identities, logging and a deterministic clock. They do not dispatch events or maintain handler statistics. The adapter supports application-thread loops (`task_name = NULL`); dedicated OS tasks and ISR posting are outside this workbench.\n", "components/esp_event/private_include/esp_event_private.h": "/*\n * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n#ifndef ESP_EVENT_PRIVATE_H_\n#define ESP_EVENT_PRIVATE_H_\n\n#include <stdbool.h>\n#include \"esp_event.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/**\n * @brief Searches handlers registered with an event loop to see if it has been registered.\n *\n * @param[in] event_loop the loop to search\n * @param[in] event_base the event base to search\n * @param[in] event_id the event id to search\n * @param[in] event_handler the event handler to look for\n *\n * @return true handler registered\n * @return false handler not registered\n *\n * @return\n * - true: Handler registered\n * - false: Handler not registered\n */\nbool esp_event_is_handler_registered(esp_event_loop_handle_t event_loop, esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler);\n\n/**\n * @brief Deinitializes the event loop library\n *\n * @return\n * - ESP_OK: Success\n * - Others: Fail\n */\nesp_err_t esp_event_loop_deinit(void);\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // #ifndef ESP_EVENT_PRIVATE_H_\n", "components/esp_event/include/esp_event.h": "/*\n * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n#ifndef ESP_EVENT_H_\n#define ESP_EVENT_H_\n\n#include \"esp_err.h\"\n\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"freertos/queue.h\"\n#include \"freertos/semphr.h\"\n\n#include \"esp_event_base.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n/// Configuration for creating event loops\ntypedef struct {\n int32_t queue_size; /**< size of the event loop queue */\n const char *task_name; /**< name of the event loop task; if NULL,\n a dedicated task is not created for event loop*/\n UBaseType_t task_priority; /**< priority of the event loop task, ignored if task name is NULL */\n uint32_t task_stack_size; /**< stack size of the event loop task, ignored if task name is NULL */\n BaseType_t task_core_id; /**< core to which the event loop task is pinned to,\n ignored if task name is NULL */\n} esp_event_loop_args_t;\n\n/**\n * @brief Create a new event loop.\n *\n * @param[in] event_loop_args configuration structure for the event loop to create\n * @param[out] event_loop handle to the created event loop\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_INVALID_ARG: event_loop_args or event_loop was NULL\n * - ESP_ERR_NO_MEM: Cannot allocate memory for event loops list\n * - ESP_FAIL: Failed to create task loop\n * - Others: Fail\n */\nesp_err_t esp_event_loop_create(const esp_event_loop_args_t *event_loop_args, esp_event_loop_handle_t *event_loop);\n\n/**\n * @brief Delete an existing event loop.\n *\n * @param[in] event_loop event loop to delete, must not be NULL\n *\n * @return\n * - ESP_OK: Success\n * - Others: Fail\n */\nesp_err_t esp_event_loop_delete(esp_event_loop_handle_t event_loop);\n\n/**\n * @brief Create default event loop\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_NO_MEM: Cannot allocate memory for event loops list\n * - ESP_ERR_INVALID_STATE: Default event loop has already been created\n * - ESP_FAIL: Failed to create task loop\n * - Others: Fail\n */\nesp_err_t esp_event_loop_create_default(void);\n\n/**\n * @brief Delete the default event loop\n *\n * @return\n * - ESP_OK: Success\n * - Others: Fail\n */\nesp_err_t esp_event_loop_delete_default(void);\n\n/**\n * @brief Dispatch events posted to an event loop.\n *\n * This function is used to dispatch events posted to a loop with no dedicated task, i.e. task name was set to NULL\n * in event_loop_args argument during loop creation. This function includes an argument to limit the amount of time\n * it runs, returning control to the caller when that time expires (or some time afterwards). There is no guarantee\n * that a call to this function will exit at exactly the time of expiry. There is also no guarantee that events have\n * been dispatched during the call, as the function might have spent all the allotted time waiting on the event queue.\n * Once an event has been dequeued, however, it is guaranteed to be dispatched. This guarantee contributes to not being\n * able to exit exactly at time of expiry as (1) blocking on internal mutexes is necessary for dispatching the dequeued\n * event, and (2) during dispatch of the dequeued event there is no way to control the time occupied by handler code\n * execution. The guaranteed time of exit is therefore the allotted time + amount of time required to dispatch\n * the last dequeued event.\n *\n * In cases where waiting on the queue times out, ESP_OK is returned and not ESP_ERR_TIMEOUT, since it is\n * normal behavior.\n *\n * @param[in] event_loop event loop to dispatch posted events from, must not be NULL\n * @param[in] ticks_to_run number of ticks to run the loop\n *\n * @note encountering an unknown event that has been posted to the loop will only generate a warning, not an error.\n *\n * @return\n * - ESP_OK: Success\n * - Others: Fail\n */\nesp_err_t esp_event_loop_run(esp_event_loop_handle_t event_loop, TickType_t ticks_to_run);\n\n/**\n * @brief Register an event handler to the system event loop (legacy).\n *\n * This function can be used to register a handler for either: (1) specific events,\n * (2) all events of a certain event base, or (3) all events known by the system event loop.\n *\n * - specific events: specify exact event_base and event_id\n * - all events of a certain base: specify exact event_base and use ESP_EVENT_ANY_ID as the event_id\n * - all events known by the loop: use ESP_EVENT_ANY_BASE for event_base and ESP_EVENT_ANY_ID as the event_id\n *\n * Registering multiple handlers to events is possible. Registering a single handler to multiple events is\n * also possible. However, registering the same handler to the same event multiple times would cause the\n * previous registrations to be overwritten.\n *\n * @param[in] event_base the base ID of the event to register the handler for\n * @param[in] event_id the ID of the event to register the handler for\n * @param[in] event_handler the handler function which gets called when the event is dispatched\n * @param[in] event_handler_arg data, aside from event data, that is passed to the handler when it is called\n *\n * @note the event loop library does not maintain a copy of event_handler_arg, therefore the user should\n * ensure that event_handler_arg still points to a valid location by the time the handler gets called\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_NO_MEM: Cannot allocate memory for the handler\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_handler_register(esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_t event_handler,\n void *event_handler_arg);\n\n/**\n * @brief Register an event handler to a specific loop (legacy).\n *\n * This function behaves in the same manner as esp_event_handler_register, except the additional\n * specification of the event loop to register the handler to.\n *\n * @param[in] event_loop the event loop to register this handler function to, must not be NULL\n * @param[in] event_base the base ID of the event to register the handler for\n * @param[in] event_id the ID of the event to register the handler for\n * @param[in] event_handler the handler function which gets called when the event is dispatched\n * @param[in] event_handler_arg data, aside from event data, that is passed to the handler when it is called\n *\n * @note the event loop library does not maintain a copy of event_handler_arg, therefore the user should\n * ensure that event_handler_arg still points to a valid location by the time the handler gets called\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_NO_MEM: Cannot allocate memory for the handler\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_handler_register_with(esp_event_loop_handle_t event_loop,\n esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_t event_handler,\n void *event_handler_arg);\n\n/**\n * @brief Register an instance of event handler to a specific loop.\n *\n * This function can be used to register a handler for either: (1) specific events,\n * (2) all events of a certain event base, or (3) all events known by the system event loop.\n *\n * - specific events: specify exact event_base and event_id\n * - all events of a certain base: specify exact event_base and use ESP_EVENT_ANY_ID as the event_id\n * - all events known by the loop: use ESP_EVENT_ANY_BASE for event_base and ESP_EVENT_ANY_ID as the event_id\n *\n * Besides the error, the function returns an instance object as output parameter to identify each registration.\n * This is necessary to remove (unregister) the registration before the event loop is deleted.\n *\n * Registering multiple handlers to events, registering a single handler to multiple events as well as registering\n * the same handler to the same event multiple times is possible.\n * Each registration yields a distinct instance object which identifies it over the registration\n * lifetime.\n *\n * @param[in] event_loop the event loop to register this handler function to, must not be NULL\n * @param[in] event_base the base ID of the event to register the handler for\n * @param[in] event_id the ID of the event to register the handler for\n * @param[in] event_handler the handler function which gets called when the event is dispatched\n * @param[in] event_handler_arg data, aside from event data, that is passed to the handler when it is called\n * @param[out] instance An event handler instance object related to the registered event handler and data, can be NULL.\n * This needs to be kept if the specific callback instance should be unregistered before deleting the whole\n * event loop. Registering the same event handler multiple times is possible and yields distinct instance\n * objects. The data can be the same for all registrations.\n * If no unregistration is needed, but the handler should be deleted when the event loop is deleted,\n * instance can be NULL.\n *\n * @note the event loop library does not maintain a copy of event_handler_arg, therefore the user should\n * ensure that event_handler_arg still points to a valid location by the time the handler gets called\n *\n * @note Calling this function with instance set to NULL is equivalent to calling esp_event_handler_register_with.\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_NO_MEM: Cannot allocate memory for the handler\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID or instance is NULL\n * - Others: Fail\n */\nesp_err_t esp_event_handler_instance_register_with(esp_event_loop_handle_t event_loop,\n esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_t event_handler,\n void *event_handler_arg,\n esp_event_handler_instance_t *instance);\n\n/**\n * @brief Register an instance of event handler to the default loop.\n *\n * This function does the same as esp_event_handler_instance_register_with, except that it registers the\n * handler to the default event loop.\n *\n * @param[in] event_base the base ID of the event to register the handler for\n * @param[in] event_id the ID of the event to register the handler for\n * @param[in] event_handler the handler function which gets called when the event is dispatched\n * @param[in] event_handler_arg data, aside from event data, that is passed to the handler when it is called\n * @param[out] instance An event handler instance object related to the registered event handler and data, can be NULL.\n * This needs to be kept if the specific callback instance should be unregistered before deleting the whole\n * event loop. Registering the same event handler multiple times is possible and yields distinct instance\n * objects. The data can be the same for all registrations.\n * If no unregistration is needed, but the handler should be deleted when the event loop is deleted,\n * instance can be NULL.\n *\n * @note the event loop library does not maintain a copy of event_handler_arg, therefore the user should\n * ensure that event_handler_arg still points to a valid location by the time the handler gets called\n *\n * @note Calling this function with instance set to NULL is equivalent to calling esp_event_handler_register.\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_NO_MEM: Cannot allocate memory for the handler\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID or instance is NULL\n * - Others: Fail\n */\nesp_err_t esp_event_handler_instance_register(esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_t event_handler,\n void *event_handler_arg,\n esp_event_handler_instance_t *instance);\n\n/**\n * @brief Unregister a handler with the system event loop (legacy).\n *\n * Unregisters a handler, so it will no longer be called during dispatch.\n * Handlers can be unregistered for any combination of event_base and event_id which were previously registered.\n * To unregister a handler, the event_base and event_id arguments must match exactly the arguments passed to\n * esp_event_handler_register() when that handler was registered. Passing ESP_EVENT_ANY_BASE and/or ESP_EVENT_ANY_ID\n * will only unregister handlers that were registered with the same wildcard arguments.\n *\n * @note When using ESP_EVENT_ANY_ID, handlers registered to specific event IDs using the same base will not be\n * unregistered. When using ESP_EVENT_ANY_BASE, events registered to specific bases will also not be\n * unregistered. This avoids accidental unregistration of handlers registered by other users or components.\n *\n * @param[in] event_base the base of the event with which to unregister the handler\n * @param[in] event_id the ID of the event with which to unregister the handler\n * @param[in] event_handler the handler to unregister\n *\n * @return ESP_OK success\n * @return ESP_ERR_INVALID_ARG invalid combination of event base and event ID\n * @return others fail\n */\nesp_err_t esp_event_handler_unregister(esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_t event_handler);\n\n/**\n * @brief Unregister a handler from a specific event loop (legacy).\n *\n * This function behaves in the same manner as esp_event_handler_unregister, except the additional specification of\n * the event loop to unregister the handler with.\n *\n * @param[in] event_loop the event loop with which to unregister this handler function, must not be NULL\n * @param[in] event_base the base of the event with which to unregister the handler\n * @param[in] event_id the ID of the event with which to unregister the handler\n * @param[in] event_handler the handler to unregister\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_handler_unregister_with(esp_event_loop_handle_t event_loop,\n esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_t event_handler);\n\n/**\n * @brief Unregister a handler instance from a specific event loop.\n *\n * Unregisters a handler instance, so it will no longer be called during dispatch.\n * Handler instances can be unregistered for any combination of event_base and event_id which were previously\n * registered. To unregister a handler instance, the event_base and event_id arguments must match exactly the\n * arguments passed to esp_event_handler_instance_register() when that handler instance was registered.\n * Passing ESP_EVENT_ANY_BASE and/or ESP_EVENT_ANY_ID will only unregister handler instances that were registered\n * with the same wildcard arguments.\n *\n * @note When using ESP_EVENT_ANY_ID, handlers registered to specific event IDs using the same base will not be\n * unregistered. When using ESP_EVENT_ANY_BASE, events registered to specific bases will also not be\n * unregistered. This avoids accidental unregistration of handlers registered by other users or components.\n *\n * @param[in] event_loop the event loop with which to unregister this handler function, must not be NULL\n * @param[in] event_base the base of the event with which to unregister the handler\n * @param[in] event_id the ID of the event with which to unregister the handler\n * @param[in] instance the instance object of the registration to be unregistered\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_handler_instance_unregister_with(esp_event_loop_handle_t event_loop,\n esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_instance_t instance);\n\n/**\n * @brief Unregister a handler from the system event loop.\n *\n * This function does the same as esp_event_handler_instance_unregister_with, except that it unregisters the\n * handler instance from the default event loop.\n *\n * @param[in] event_base the base of the event with which to unregister the handler\n * @param[in] event_id the ID of the event with which to unregister the handler\n * @param[in] instance the instance object of the registration to be unregistered\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_handler_instance_unregister(esp_event_base_t event_base,\n int32_t event_id,\n esp_event_handler_instance_t instance);\n\n/**\n * @brief Posts an event to the system default event loop. The event loop library keeps a copy of event_data and manages\n * the copy's lifetime automatically (allocation + deletion); this ensures that the data the\n * handler receives is always valid.\n *\n * @param[in] event_base the event base that identifies the event\n * @param[in] event_id the event ID that identifies the event\n * @param[in] event_data the data, specific to the event occurrence, that gets passed to the handler\n * @param[in] event_data_size the size of the event data\n * @param[in] ticks_to_wait number of ticks to block on a full event queue\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_TIMEOUT: Time to wait for event queue to unblock expired,\n * queue full when posting from ISR\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_post(esp_event_base_t event_base,\n int32_t event_id,\n const void *event_data,\n size_t event_data_size,\n TickType_t ticks_to_wait);\n\n/**\n * @brief Posts an event to the specified event loop. The event loop library keeps a copy of event_data and manages\n * the copy's lifetime automatically (allocation + deletion); this ensures that the data the\n * handler receives is always valid.\n *\n * This function behaves in the same manner as esp_event_post, except the additional specification of the event loop\n * to post the event to.\n *\n * @param[in] event_loop the event loop to post to, must not be NULL\n * @param[in] event_base the event base that identifies the event\n * @param[in] event_id the event ID that identifies the event\n * @param[in] event_data the data, specific to the event occurrence, that gets passed to the handler\n * @param[in] event_data_size the size of the event data\n * @param[in] ticks_to_wait number of ticks to block on a full event queue\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_TIMEOUT: Time to wait for event queue to unblock expired,\n * queue full when posting from ISR\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID\n * - Others: Fail\n */\nesp_err_t esp_event_post_to(esp_event_loop_handle_t event_loop,\n esp_event_base_t event_base,\n int32_t event_id,\n const void *event_data,\n size_t event_data_size,\n TickType_t ticks_to_wait);\n\n#if CONFIG_ESP_EVENT_POST_FROM_ISR\n/**\n * @brief Special variant of esp_event_post for posting events from interrupt handlers.\n *\n * @param[in] event_base the event base that identifies the event\n * @param[in] event_id the event ID that identifies the event\n * @param[in] event_data the data, specific to the event occurrence, that gets passed to the handler\n * @param[in] event_data_size the size of the event data; max is 4 bytes\n * @param[out] task_unblocked an optional parameter (can be NULL) which indicates that an event task with\n * higher priority than currently running task has been unblocked by the posted event;\n * a context switch should be requested before the interrupt is existed.\n *\n * @note this function is only available when CONFIG_ESP_EVENT_POST_FROM_ISR is enabled\n * @note when this function is called from an interrupt handler placed in IRAM, this function should\n * be placed in IRAM as well by enabling CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR\n *\n * @return\n * - ESP_OK: Success\n * - ESP_FAIL: Event queue for the default event loop full\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID,\n * data size of more than 4 bytes\n * - Others: Fail\n */\nesp_err_t esp_event_isr_post(esp_event_base_t event_base,\n int32_t event_id,\n const void *event_data,\n size_t event_data_size,\n BaseType_t *task_unblocked);\n\n/**\n * @brief Special variant of esp_event_post_to for posting events from interrupt handlers\n *\n * @param[in] event_loop the event loop to post to, must not be NULL\n * @param[in] event_base the event base that identifies the event\n * @param[in] event_id the event ID that identifies the event\n * @param[in] event_data the data, specific to the event occurrence, that gets passed to the handler\n * @param[in] event_data_size the size of the event data\n * @param[out] task_unblocked an optional parameter (can be NULL) which indicates that an event task with\n * higher priority than currently running task has been unblocked by the posted event;\n * a context switch should be requested before the interrupt is existed.\n *\n * @note this function is only available when CONFIG_ESP_EVENT_POST_FROM_ISR is enabled\n * @note when this function is called from an interrupt handler placed in IRAM, this function should\n * be placed in IRAM as well by enabling CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR\n *\n * @return\n * - ESP_OK: Success\n * - ESP_FAIL: Event queue for the loop full\n * - ESP_ERR_INVALID_ARG: Invalid combination of event base and event ID,\n * data size of more than 4 bytes\n * - Others: Fail\n */\nesp_err_t esp_event_isr_post_to(esp_event_loop_handle_t event_loop,\n esp_event_base_t event_base,\n int32_t event_id,\n const void *event_data,\n size_t event_data_size,\n BaseType_t *task_unblocked);\n#endif\n\n/**\n * @brief Dumps statistics of all event loops.\n *\n * Dumps event loop info in the format:\n *\n @verbatim\n event loop\n handler\n handler\n ...\n event loop\n handler\n handler\n ...\n\n where:\n\n event loop\n format: address,name rx:total_received dr:total_dropped\n where:\n address - memory address of the event loop\n name - name of the event loop, 'none' if no dedicated task\n total_received - number of successfully posted events\n total_dropped - number of events unsuccessfully posted due to queue being full\n\n handler\n format: address ev:base,id inv:total_invoked run:total_runtime\n where:\n address - address of the handler function\n base,id - the event specified by event base and ID this handler executes\n total_invoked - number of times this handler has been invoked\n total_runtime - total amount of time used for invoking this handler\n\n @endverbatim\n *\n * @param[in] file the file stream to output to\n *\n * @note this function is a noop when CONFIG_ESP_EVENT_LOOP_PROFILING is disabled\n *\n * @return\n * - ESP_OK: Success\n * - ESP_ERR_NO_MEM: Cannot allocate memory for event loops list\n * - Others: Fail\n */\nesp_err_t esp_event_dump(FILE *file);\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // #ifndef ESP_EVENT_H_\n", "components/esp_event/include/esp_event_base.h": "/*\n * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n#pragma once\n\n#include <stdint.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// Defines for declaring and defining event base\n#define ESP_EVENT_DECLARE_BASE(id) extern esp_event_base_t const id\n#define ESP_EVENT_DEFINE_BASE(id) esp_event_base_t const id = #id\n\n// Event loop library types\ntypedef const char* esp_event_base_t; /**< unique pointer to a subsystem that exposes events */\ntypedef void* esp_event_loop_handle_t; /**< a number that identifies an event with respect to a base */\ntypedef void (*esp_event_handler_t)(void* event_handler_arg,\n esp_event_base_t event_base,\n int32_t event_id,\n void* event_data); /**< function called when an event is posted to the queue */\ntypedef void* esp_event_handler_instance_t; /**< context identifying an instance of a registered event handler */\n\n// Defines for registering/unregistering event handlers\n#define ESP_EVENT_ANY_BASE NULL /**< register handler for any event base */\n#define ESP_EVENT_ANY_ID -1 /**< register handler for any event id */\n\n#ifdef __cplusplus\n}\n#endif\n", "docs/platform.md": "# Software services\n\nThe adapter provides finite byte queues, recursive and ordinary mutexes, logical task handles and a virtual tick clock. `xTaskGetTickCount` observes ticks and `esp_timer_get_time` observes microseconds without advancing time. One tick is 1000 microseconds; applications may advance time with `os_advance` to model callback work.\n\n`os_schedule(delay, task, action, argument)` schedules one generic action. When an OS wait covers its due tick, the service runs that action with the supplied task identity and then restores the waiting task identity. A wait shorter than the scheduled delay reaches its deadline without running the action. Queue operations copy arbitrary bytes and decide only from queue occupancy and the supplied waiting interval. `os_cancel` cancels an outstanding action.\n\nThe application may use these services to coordinate producers and consumers without wall-clock races. No service interprets event bases, IDs, callbacks, profiling information or loop state. Dedicated task creation is unsupported and reports failure; application-thread loops are the supported execution mode.\n", "docs/event-contract.md": "# Event application contract\n\nR01. Each loop owns an independent FIFO event queue and its handler registrations. A loop without a dedicated task is dispatched by the application, and successfully dequeued events are delivered before that dispatch call returns.\n\nR02. A finite dispatch call returns control when its allotted ticks have expired, allowing the final dequeued event and its callbacks to complete. Waiting on an empty queue is a normal successful dispatch result.\n\nR03. A registration for any base and any ID matches all events; a registration for one base and any ID matches that base; a registration for one base and one ID matches that pair. Every matching registered handler is invoked once for an event, and nonmatching handlers are not invoked.\n\nR04. A callback receives its registration context, event base, event ID, and the contents supplied when the event was posted. Posted nonempty data is copied before a successful post returns; null or zero-sized data is delivered as null.\n\nR05. Instance registrations are independently removable by their instance handle. Legacy registration of the same function for the same base and ID updates its argument instead of adding a second registration. Unregistering an absent legacy handler succeeds without changing other registrations. Removing a registration prevents its future delivery; deleting a loop discards its queued events and registrations without affecting other loops.\n\nR06. A producer may wait up to `ticks_to_wait` for queue space. A post succeeds if space becomes available within that wait and otherwise returns `ESP_ERR_TIMEOUT`; zero wait returns immediately when the queue is full. A successful finite dispatch returns the calling task to ordinary application use.\n\nR07. With profiling enabled, the public dump includes all current loops and current registrations. A loop's received counter is the number of successful posts, and its dropped counter is the number of posts rejected because the queue is full. A registration's invocation counter is its actual callback count, and its runtime is the nonnegative accumulated time spent invoking that handler. Invocation and runtime totals accumulate for the lifetime of that registration.\n\nR08. Dump addresses, allocation order and presentation whitespace are diagnostic details. Base, ID, counters and runtime carry the public meaning. Empty loops have no handler records, and deleted loops no longer appear.\n\nR09. Registering or unregistering any base with a specific ID returns `ESP_ERR_INVALID_ARG`. Posting any base or any ID returns `ESP_ERR_INVALID_ARG`. An instance unregister with a null handle returns `ESP_ERR_INVALID_ARG`. Rejected arguments do not enqueue events.\n\nThe API comments in `components/esp_event/include/esp_event.h` and `esp_event_base.h` supply the interface signatures, parameter meanings and return values. The contract above organizes the application's use of those interfaces.\n", "platform/os.c": "/* General byte queues, recursive mutexes, task identities and a virtual clock.\n * A scheduled action runs on its specified logical task during an OS wait.\n * SPDX-License-Identifier: Apache-2.0\n */\n#include \"os.h\"\n#include \"freertos/task.h\"\n#include \"freertos/queue.h\"\n#include \"freertos/semphr.h\"\n#include <stdlib.h>\n#include <string.h>\n#include <stdarg.h>\n#include <stdio.h>\nstruct os_queue { unsigned cap,head,count; size_t size; unsigned char *data; };\nstruct os_mutex { TaskHandle_t owner; unsigned depth; int recursive; };\nstatic TickType_t clock_ticks;\nstatic TaskHandle_t current=(void *)(uintptr_t)1;\nstatic struct { TickType_t at; TaskHandle_t task; void (*fn)(void *); void *arg; } alarm_event;\nvoid os_advance(TickType_t n) { clock_ticks+=n; }\nTickType_t xTaskGetTickCount(void) { return clock_ticks; }\nint64_t esp_timer_get_time(void) { return (int64_t)clock_ticks*1000; }\nTaskHandle_t xTaskGetCurrentTaskHandle(void) { return current; }\nvoid os_schedule(TickType_t delay,TaskHandle_t task,void (*fn)(void *),void *arg) {\n assert(!alarm_event.fn); alarm_event.at=clock_ticks+delay; alarm_event.task=task; alarm_event.fn=fn; alarm_event.arg=arg;\n}\nvoid os_cancel(void) { alarm_event.fn=NULL; }\nstatic int wait_service(TickType_t ticks) {\n if (alarm_event.fn && (uint32_t)(alarm_event.at-clock_ticks)<=ticks) {\n TaskHandle_t saved=current; void (*fn)(void *)=alarm_event.fn; void *arg=alarm_event.arg;\n clock_ticks=alarm_event.at;current=alarm_event.task;alarm_event.fn=NULL;fn(arg);current=saved;return 1;\n }\n if(ticks!=portMAX_DELAY) clock_ticks+=ticks;\n return 0;\n}\nQueueHandle_t xQueueCreate(unsigned cap,size_t size) {\n if(!cap || !size)return NULL;QueueHandle_t q=calloc(1,sizeof(*q));\n if(q){q->data=calloc(cap,size);q->cap=cap;q->size=size;if(!q->data){free(q);return NULL;}}return q;\n}\nBaseType_t xQueueSendToBack(QueueHandle_t q,const void *item,TickType_t ticks) {\n if(q->count==q->cap){if(!ticks || !wait_service(ticks) || q->count==q->cap)return pdFALSE;}\n memcpy(q->data+((q->head+q->count)%q->cap)*q->size,item,q->size);q->count++;return pdTRUE;\n}\nBaseType_t xQueueReceive(QueueHandle_t q,void *item,TickType_t ticks) {\n if(!q->count){if(!ticks || !wait_service(ticks) || !q->count)return pdFALSE;}\n memcpy(item,q->data+q->head*q->size,q->size);q->head=(q->head+1)%q->cap;q->count--;return pdTRUE;\n}\nvoid vQueueDelete(QueueHandle_t q){free(q->data);free(q);}\nstatic SemaphoreHandle_t create_mutex(int recursive){SemaphoreHandle_t m=calloc(1,sizeof(*m));if(m)m->recursive=recursive;return m;}\nSemaphoreHandle_t xSemaphoreCreateMutex(void){return create_mutex(0);}\nSemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void){return create_mutex(1);}\nBaseType_t xSemaphoreTake(SemaphoreHandle_t m,TickType_t ticks){\n if(m->depth && !(m->recursive && m->owner==current)){\n if(!ticks || !wait_service(ticks) || m->depth)return pdFALSE;\n }m->owner=current;m->depth++;return pdTRUE;\n}\nBaseType_t xSemaphoreGive(SemaphoreHandle_t m){if(!m->depth || m->owner!=current)return pdFALSE;if(!--m->depth)m->owner=NULL;return pdTRUE;}\nBaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t m,TickType_t ticks){return xSemaphoreTake(m,ticks);}\nBaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t m){return xSemaphoreGive(m);}\nvoid vSemaphoreDelete(SemaphoreHandle_t m){free(m);}\nvoid os_enter(portMUX_TYPE *m){++*m;}\nvoid os_exit(portMUX_TYPE *m){assert(*m>0);--*m;}\nvoid os_log(const char *tag,const char *fmt,...){\n if(getenv(\"OS_VERBOSE\")){va_list ap;va_start(ap,fmt);fprintf(stderr,\"%s: \",tag);vfprintf(stderr,fmt,ap);fputc('\\n',stderr);va_end(ap);}\n}\nBaseType_t xTaskCreatePinnedToCore(void (*fn)(void *),const char *name,uint32_t stack,void *arg,unsigned priority,TaskHandle_t *task,int core){\n (void)fn;(void)name;(void)stack;(void)arg;(void)priority;(void)task;(void)core;\n /* Dedicated task creation is outside this application-thread adapter. */return pdFALSE;\n}\nvoid vTaskSuspend(TaskHandle_t task){(void)task;abort();}\nvoid vTaskDelete(TaskHandle_t task){(void)task;abort();}\n", "platform/os.h": "#ifndef PORT_OS_H\n#define PORT_OS_H\n#include \"freertos/FreeRTOS.h\"\nvoid os_advance(TickType_t);\nvoid os_schedule(TickType_t delay,TaskHandle_t task,void (*action)(void *),void *arg);\nvoid os_cancel(void);\n#endif\n", "platform/esp_err.h": "#ifndef PORT_ESP_ERR_H\n#define PORT_ESP_ERR_H\ntypedef int esp_err_t;\n#define ESP_OK 0\n#define ESP_FAIL -1\n#define ESP_ERR_NO_MEM 0x101\n#define ESP_ERR_INVALID_ARG 0x102\n#define ESP_ERR_INVALID_STATE 0x103\n#define ESP_ERR_NOT_FOUND 0x105\n#define ESP_ERR_TIMEOUT 0x107\n#endif\n", "platform/esp_log.h": "#ifndef PORT_ESP_LOG_H\n#define PORT_ESP_LOG_H\n#include <stdio.h>\n#include <inttypes.h>\nvoid os_log(const char *,const char *,...);\n#define ESP_LOGD(tag,...) os_log(tag,__VA_ARGS__)\n#define ESP_LOGE(tag,...) os_log(tag,__VA_ARGS__)\n#define ESP_LOGW(tag,...) os_log(tag,__VA_ARGS__)\n#endif\n", "platform/esp_timer.h": "#ifndef PORT_ESP_TIMER_H\n#define PORT_ESP_TIMER_H\n#include <stdint.h>\nint64_t esp_timer_get_time(void);\n#endif\n", "platform/freertos/FreeRTOS.h": "/* Local deterministic OS service adapter. SPDX-License-Identifier: Apache-2.0 */\n#ifndef PORT_FREERTOS_H\n#define PORT_FREERTOS_H\n#include <stdint.h>\n#include <stddef.h>\n#include <stdio.h>\n#include <assert.h>\n#include <inttypes.h>\n#include <sys/queue.h>\n#ifndef SLIST_FOREACH_SAFE\n#define SLIST_FOREACH_SAFE(v,h,f,t) for ((v)=SLIST_FIRST(h); (v) && ((t)=SLIST_NEXT(v,f),1); (v)=(t))\n#endif\ntypedef uint32_t TickType_t;\ntypedef int BaseType_t;\ntypedef unsigned UBaseType_t;\ntypedef void *TaskHandle_t;\ntypedef int portMUX_TYPE;\n#define portMUX_INITIALIZER_UNLOCKED 0\n#define portMAX_DELAY UINT32_MAX\n#define pdTRUE 1\n#define pdFALSE 0\n#define pdPASS 1\n#define configUSE_16_BIT_TICKS 0\n#define CONFIG_ESP_EVENT_LOOP_PROFILING 1\n#define CONFIG_ESP_EVENT_POST_FROM_ISR 0\nvoid os_enter(portMUX_TYPE *);\nvoid os_exit(portMUX_TYPE *);\n#define portENTER_CRITICAL(m) os_enter(m)\n#define portEXIT_CRITICAL(m) os_exit(m)\n#endif\n", "platform/freertos/semphr.h": "#ifndef PORT_SEMPHR_H\n#define PORT_SEMPHR_H\n#include \"FreeRTOS.h\"\ntypedef struct os_mutex *SemaphoreHandle_t;\nSemaphoreHandle_t xSemaphoreCreateMutex(void);\nSemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void);\nBaseType_t xSemaphoreTake(SemaphoreHandle_t,TickType_t);\nBaseType_t xSemaphoreGive(SemaphoreHandle_t);\nBaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t,TickType_t);\nBaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t);\nvoid vSemaphoreDelete(SemaphoreHandle_t);\n#endif\n", "platform/freertos/task.h": "#ifndef PORT_TASK_H\n#define PORT_TASK_H\n#include \"FreeRTOS.h\"\nTickType_t xTaskGetTickCount(void);\nTaskHandle_t xTaskGetCurrentTaskHandle(void);\nBaseType_t xTaskCreatePinnedToCore(void (*)(void *),const char *,uint32_t,void *,unsigned,TaskHandle_t *,int);\nvoid vTaskSuspend(TaskHandle_t);\nvoid vTaskDelete(TaskHandle_t);\n#endif\n", "platform/freertos/queue.h": "#ifndef PORT_QUEUE_H\n#define PORT_QUEUE_H\n#include \"FreeRTOS.h\"\ntypedef struct os_queue *QueueHandle_t;\nQueueHandle_t xQueueCreate(unsigned,size_t);\nBaseType_t xQueueSendToBack(QueueHandle_t,const void *,TickType_t);\nBaseType_t xQueueReceive(QueueHandle_t,void *,TickType_t);\nvoid vQueueDelete(QueueHandle_t);\n#endif\n", "observer.c": "/* Raw public-API observations; no expected values. SPDX-License-Identifier: Apache-2.0 */\n#include \"esp_event.h\"\n#include \"os.h\"\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <unistd.h>\nstatic const char *bases[]={\"SENSOR\",\"CONTROL\",\"STATUS\"};\nstatic esp_event_loop_handle_t loops[4];\nstatic esp_event_handler_instance_t instances[32];\nstatic struct context {int tag,work;} ctx[32];\nstatic int line_no;\nstatic struct delivery {int loop,ticks;} scheduled;\nstatic void callback(void *arg,esp_event_base_t base,int32_t id,void *data){\n struct context *c=arg;unsigned *p=data;\n printf(\"CB %d %s %d %d %u %u\\n\",c->tag,base,(int)id,!!p,p?p[0]:0,p?p[1]:0);\n os_advance(c->work);\n}\nstatic void consume(void *arg){struct delivery *d=arg;int r=esp_event_loop_run(loops[d->loop],d->ticks);printf(\"CONSUMER %d\\n\",r);}\nint main(void){\n char op[24];int a,b,c,d,e,f,r=0;unsigned x,y;int has;\n setvbuf(stdout,NULL,_IONBF,0);printf(\"IDENTITY %u %u\\n\",(unsigned)getuid(),(unsigned)getgid());\n while(scanf(\"%23s\",op)==1){++line_no;\n if(!strcmp(op,\"create\")){scanf(\"%d%d\",&a,&b);esp_event_loop_args_t args={.queue_size=b,.task_name=NULL};r=esp_event_loop_create(&args,&loops[a]);}\n else if(!strcmp(op,\"reg\")){scanf(\"%d%d%d%d%d%d\",&a,&b,&c,&d,&e,&f);ctx[b]=(struct context){b,e};r=f?esp_event_handler_instance_register_with(loops[a],c<0?ESP_EVENT_ANY_BASE:bases[c],d,callback,&ctx[b],&instances[b]):esp_event_handler_register_with(loops[a],c<0?ESP_EVENT_ANY_BASE:bases[c],d,callback,&ctx[b]);}\n else if(!strcmp(op,\"unreg\")){scanf(\"%d%d%d%d%d\",&a,&b,&c,&d,&f);r=f?esp_event_handler_instance_unregister_with(loops[a],c<0?ESP_EVENT_ANY_BASE:bases[c],d,instances[b]):esp_event_handler_unregister_with(loops[a],c<0?ESP_EVENT_ANY_BASE:bases[c],d,callback);}\n else if(!strcmp(op,\"post\")){scanf(\"%d%d%d%u%u%d%d\",&a,&c,&d,&x,&y,&has,&e);unsigned data[]={x,y};r=esp_event_post_to(loops[a],c<0?ESP_EVENT_ANY_BASE:bases[c],d,has?data:NULL,has?sizeof(data):0,e);data[0]=data[1]=0;}\n else if(!strcmp(op,\"run\")){scanf(\"%d%d\",&a,&b);r=esp_event_loop_run(loops[a],b);}\n else if(!strcmp(op,\"schedule\")){scanf(\"%d%d%d\",&a,&b,&c);scheduled=(struct delivery){a,c};os_schedule(b,(void *)(uintptr_t)2,consume,&scheduled);r=0;}\n else if(!strcmp(op,\"cancel\")){os_cancel();r=0;}\n else if(!strcmp(op,\"dump\")){printf(\"DUMP %d\\n\",line_no);r=esp_event_dump(stdout);printf(\"ENDDUMP\\n\");}\n else if(!strcmp(op,\"delete\")){scanf(\"%d\",&a);r=esp_event_loop_delete(loops[a]);loops[a]=NULL;}\n else return 3;\n printf(\"R %d %d\\n\",line_no,r);\n }\n return 0;\n}\n"}
|