| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-20 21:41:37 -05:00
										 |  |  | /**
 | 
					
						
							|  |  |  | ** \defgroup taskstub Task Stub | 
					
						
							|  |  |  | ** Task Stub is a poorly-named representation of a remote Task that can be | 
					
						
							|  |  |  | ** exposed to JS. | 
					
						
							|  |  |  | ** @{ | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | #include "quickjs.h"
 | 
					
						
							| 
									
										
										
										
											2023-05-21 21:36:51 +00:00
										 |  |  | #include "uv.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | /** A task identifier. */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | typedef int taskid_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | /** A packet stream. */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | typedef struct _tf_packetstream_t tf_packetstream_t; | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** A task. */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | typedef struct _tf_task_t tf_task_t; | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** A handle to another task. */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | typedef struct _tf_taskstub_t tf_taskstub_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | /** Initialize task stub.  Call before using the rest. */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | void tf_taskstub_startup(); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Register the task stub script interface. | 
					
						
							|  |  |  | ** @param context The JS context. | 
					
						
							|  |  |  | ** @return The task stub constructor. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-10-24 15:46:30 +00:00
										 |  |  | JSValue tf_taskstub_register(JSContext* context); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Get a unique identifier for the task stub. | 
					
						
							|  |  |  | ** @param stub The task stub. | 
					
						
							|  |  |  | ** @return An identifier for the stub. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | taskid_t tf_taskstub_get_id(const tf_taskstub_t* stub); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Get the JS object representing the task stub. | 
					
						
							|  |  |  | ** @param stub The task stub. | 
					
						
							|  |  |  | ** @return The JS object. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | JSValue tf_taskstub_get_task_object(const tf_taskstub_t* stub); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Get the packet stream that can be used to communicate with the task stub. | 
					
						
							|  |  |  | ** @param stub The task stub. | 
					
						
							|  |  |  | ** @return The packet stream. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | tf_packetstream_t* tf_taskstub_get_stream(const tf_taskstub_t* stub); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Get the task owning the task stub. | 
					
						
							|  |  |  | ** @param stub The task stub. | 
					
						
							|  |  |  | ** @return The task from which the task stub was created. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | tf_task_t* tf_taskstub_get_owner(const tf_taskstub_t* stub); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Create a task stub representing the parent task of the running process. | 
					
						
							|  |  |  | ** @param task The running task. | 
					
						
							|  |  |  | ** @param file A file descriptor of a pipe connected to a parent process task. | 
					
						
							|  |  |  | ** @return The created task stub. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | tf_taskstub_t* tf_taskstub_create_parent(tf_task_t* task, uv_file file); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Report an error to a task stub. | 
					
						
							|  |  |  | ** @param stub The stub to which to report th eerror. | 
					
						
							|  |  |  | ** @param error The error to report. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | void tf_taskstub_on_error(tf_taskstub_t* stub, JSValue error); | 
					
						
							| 
									
										
										
										
											2024-03-01 21:18:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  | ** Print to a task stub. | 
					
						
							|  |  |  | ** @param stub The task stub to which to print. | 
					
						
							|  |  |  | ** @param arguments The values to print. | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2022-02-13 22:39:22 +00:00
										 |  |  | void tf_taskstub_on_print(tf_taskstub_t* stub, JSValue arguments); | 
					
						
							| 
									
										
										
										
											2024-02-20 21:41:37 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** @} */ |