Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Update ServiceWrapper to use inheritance
Browse files Browse the repository at this point in the history
Now with FreeBASIC 0.24, inheritance usage is possible.

This change removes the need to leverage on 'extra' to keep the instance
reference and also properly initializes 'base'.
  • Loading branch information
luislavena committed Aug 21, 2012
1 parent 690f997 commit 71a62ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
5 changes: 1 addition & 4 deletions inc/service_wrapper.bi
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
#define trace(msg)
#endif

type ServiceWrapper
type ServiceWrapper extends MiniService
declare constructor()
declare destructor()

declare sub run()

private:
base as MiniService ptr
config as ConfigurationFile ptr
child as ConsoleProcess ptr

Expand Down
45 changes: 19 additions & 26 deletions src/service_wrapper.bas
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include once "service_wrapper.bi"

constructor ServiceWrapper()
trace("initialize base and set callbacks")
base = new MiniService("ServiceWrapper")
base->onInit = @ServiceWrapper.onInit
base->onStart = @ServiceWrapper.onStart
base->onStop = @ServiceWrapper.onStop
base->extra = @this
base("ServiceWrapper")

trace("set callbacks")
base.onInit = @ServiceWrapper.onInit
base.onStart = @ServiceWrapper.onStart
base.onStop = @ServiceWrapper.onStop
end constructor

destructor ServiceWrapper()
trace("unset everything and delete config, child and base")
trace("unset everything and delete config and child")
if (config) then
delete config
end if
Expand All @@ -19,25 +19,18 @@ destructor ServiceWrapper()
delete child
end if

base->onInit = 0
base->onStart = 0
base->onStop = 0
base->extra = 0
delete base
base.onInit = 0
base.onStart = 0
base.onStop = 0
end destructor

sub ServiceWrapper.run()
trace("base->run()")
base->run()
end sub

sub ServiceWrapper.onInit(byval base as MiniService ptr)
var this = cast(ServiceWrapper ptr, base->extra)
sub ServiceWrapper.onInit(byval service as MiniService ptr)
var this = cast(ServiceWrapper ptr, service)

trace("System PATH: " + Environ("PATH"))

trace("initialize config with file '" + base->command_line + "'")
this->config = new ConfigurationFile(base->command_line)
trace("initialize config with file '" + this->command_line + "'")
this->config = new ConfigurationFile(this->command_line)
var config = this->config '# shorthand

trace("executable: " + config->executable)
Expand Down Expand Up @@ -70,11 +63,11 @@ sub ServiceWrapper.onInit(byval base as MiniService ptr)
trace("done with onInit")
end sub

sub ServiceWrapper.onStart(byval base as MiniService ptr)
var this = cast(ServiceWrapper ptr, base->extra)
sub ServiceWrapper.onStart(byval service as MiniService ptr)
var this = cast(ServiceWrapper ptr, service)

trace("waiting during the running state")
do while (base->state = MiniService.States.Running)
do while (this->state = MiniService.States.Running)
sleep 100
loop

Expand All @@ -91,8 +84,8 @@ sub ServiceWrapper.onStart(byval base as MiniService ptr)
trace("done with onStart")
end sub

sub ServiceWrapper.onStop(byval base as MiniService ptr)
var this = cast(ServiceWrapper ptr, base->extra)
sub ServiceWrapper.onStop(byval service as MiniService ptr)
var this = cast(ServiceWrapper ptr, service)

if (this->child) then
'# FIXME: ping ServiceManager think we are dead...
Expand Down

0 comments on commit 71a62ea

Please sign in to comment.