Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Nerodon

Background processes (RC API? Daemons? Event.Listen?)

Question

Hello everyone.

 

I'm pretty new to OC but really enjoying it so far.

I've been writing simple robot automation programs and they work out well for me I have trouble grasping some of the more OS related features such as signals/events and the way I can implement services/daemons.

 

I am implementing a simple network protocol in which servers acting as routers and other computers send packets back and forth to build ARP-like address tables, my end goal being a simplified IP system that routes packets efficiently through a large network using conventional format IPv4 addresses and DNS servers.

 

Essentially, here is my challenge:

I want to have my computer listen and answer modem signals while not disrupting/stopping an active program or the shell. So I have a few questions to ask.

 

1) What is the best way to do this?

 

2) Information is very hard to just come by, I have read a lot about listening to events and then using callback functions, but how does that work outside of an actual program? 

 

3)I read in the API documentation about events, that "Driver Mode" was a way to possibly run listeners alongside the shell but no further information is available about this. What does driver mode refer to?

 

4) What is the RC API, and how/what does it actually do? It is pretty weakly documented and it almost looks like it is what I need if we are talking about Daemons running along side other programs or the shell.

 

Essentially, a background process. I do understand that, technically, without true parallel processing, the callbacks will need to finish before the computer will be usable again (I think) but my callbacks are intended to be very short quick message replies or quick file writes.

 

I appreciate any help! Thanks!

 

 

 

 

 

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  • Solution

Hello ! 

 

1 ) You'll want to use driver mode (aka event.listen, a look in the event api's documentation will help you).

 

2 ) Well, your non-foreground program is still a program, so you define your callback function (it takes all the arguments of the signal, look in the signals page of the doc), and register it with event.listen("event_type", yourfunction).

 

3 ) Driver mode is a way for OpenOS to handle events, it uses event.listen(event, function) and event.ignore(event, function), the whole thing runs in background.

 

4 ) rc is just like a daemon manager...Or rather it starts things at boot if you configure it to do so, and it calls functions of that thing when you use rc. You can look at /etc/rc.d/example.lua, but basically you have a file with many functions, all of which represent a rc call (just like rc <service> <call>), one of these can be start(config), which will be called at boot if the name without the ".lua" of your file is in the "enabled" table of rc.cfg -that's a Lua file btw- and will be passed the variable that has the name of your service in rc.cfg as first argument.

 

Also, rc and driver mode aren't mutually exclusive, they work great together, actually.

 

I hope I've been clear, I'm not that great at explaining stuff.

Link to post
Share on other sites
  • 0

Thank you, this indeed clears up a lot.

So I basically just need to fall in love with registering events as this seems to be the only way to run things in the background.

 

That's pretty much exactly what I was looking for, everything I was looking to do pretty much works under callbacks from modem_messages so far but I can see many other ways to use events with different signals, such as timers etc.

 

Thanks

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.