mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 15:48:19 +00:00
Make SendEvent callable from all threads
This commit refactors the SendEvent call and moves it from the Input ReaderBackend to to MsgThread. This allows all other types of threads to access this functionality. This necessitated a few more changes. Most importantly, one of the ValueToVal methods was moved over to SerialTypes. Whereit arguably belongs - there was nothing that was input-framework specific in that method - and the functionality could come in useful in a number of cases.
This commit is contained in:
parent
9dec370048
commit
034304b9d5
12 changed files with 353 additions and 331 deletions
|
@ -126,6 +126,31 @@ private:
|
|||
|
||||
}
|
||||
|
||||
// An event that the child wants to pass into the main event queue
|
||||
class SendEventMessage final : public OutputMessage<MsgThread> {
|
||||
public:
|
||||
SendEventMessage(MsgThread* thread, const char* name, const int num_vals, Value* *val)
|
||||
: OutputMessage<MsgThread>("SendEvent", thread),
|
||||
name(copy_string(name)), num_vals(num_vals), val(val) {}
|
||||
|
||||
~SendEventMessage() override { delete [] name; }
|
||||
|
||||
bool Process() override
|
||||
{
|
||||
bool success = thread_mgr->SendEvent(Object(), name, num_vals, val);
|
||||
|
||||
if ( ! success )
|
||||
reporter->Error("SendEvent for event %s failed", name);
|
||||
|
||||
return true; // We do not want to die if sendEvent fails because the event did not return.
|
||||
}
|
||||
|
||||
private:
|
||||
const char* name;
|
||||
const int num_vals;
|
||||
Value* *val;
|
||||
};
|
||||
|
||||
////// Methods.
|
||||
|
||||
Message::~Message()
|
||||
|
@ -363,6 +388,11 @@ void MsgThread::SendOut(BasicOutputMessage* msg, bool force)
|
|||
flare.Fire();
|
||||
}
|
||||
|
||||
void MsgThread::SendEvent(const char* name, const int num_vals, Value* *vals)
|
||||
{
|
||||
SendOut(new SendEventMessage(this, name, num_vals, vals));
|
||||
}
|
||||
|
||||
BasicOutputMessage* MsgThread::RetrieveOut()
|
||||
{
|
||||
BasicOutputMessage* msg = queue_out.Get();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue