X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=examples%2Fcmd%2Fexample-xapp.go;h=f2ea45685a2048adcc9b6214fe33a013e6ecabee;hb=refs%2Fheads%2Falarm_wa;hp=acb0b8d91448b1f88b2ced58892732d6b1d3744b;hpb=3a616f30fbc699858c708187378dc0c87843d31e;p=ric-plt%2Fxapp-frame.git diff --git a/examples/cmd/example-xapp.go b/examples/cmd/example-xapp.go index acb0b8d..f2ea456 100755 --- a/examples/cmd/example-xapp.go +++ b/examples/cmd/example-xapp.go @@ -30,7 +30,6 @@ import ( // This could be defined in types.go type ExampleXapp struct { - msgChan chan *xapp.RMRParams stats map[string]xapp.Counter rmrReady bool waitForSdl bool @@ -55,25 +54,6 @@ func (e *ExampleXapp) handleRICExampleMessage(ranName string, r *xapp.RMRParams) } } -func (e *ExampleXapp) messageLoop() { - for { - msg := <-e.msgChan - id := xapp.Rmr.GetRicMessageName(msg.Mtype) - defer xapp.Rmr.Free(msg.Mbuf) - - xapp.Logger.Info("Message received: name=%s meid=%s subId=%d txid=%s len=%d", id, msg.Meid.RanName, msg.SubId, msg.Xid, msg.PayloadLen) - - switch id { - case "RIC_INDICATION": - e.handleRICIndication(msg.Meid.RanName, msg) - case "RIC_EXAMPLE_MESSAGE": - e.handleRICExampleMessage(msg.Meid.RanName, msg) - default: - xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype) - } - } -} - func (e *ExampleXapp) Subscribe() { // Setup response callback to handle subscription response from SubMgr xapp.Subscription.SetResponseCB(func(resp *clientmodel.SubscriptionResponse) { @@ -115,8 +95,24 @@ func (e *ExampleXapp) Subscribe() { } } -func (e *ExampleXapp) Consume(rp *xapp.RMRParams) (err error) { - e.msgChan <- rp +func (e *ExampleXapp) Consume(msg *xapp.RMRParams) (err error) { + id := xapp.Rmr.GetRicMessageName(msg.Mtype) + + xapp.Logger.Info("Message received: name=%s meid=%s subId=%d txid=%s len=%d", id, msg.Meid.RanName, msg.SubId, msg.Xid, msg.PayloadLen) + + switch id { + case "RIC_INDICATION": + e.handleRICIndication(msg.Meid.RanName, msg) + case "RIC_EXAMPLE_MESSAGE": + e.handleRICExampleMessage(msg.Meid.RanName, msg) + default: + xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype) + } + + defer func() { + xapp.Rmr.Free(msg.Mbuf) + msg.Mbuf = nil + }() return } @@ -145,7 +141,6 @@ func (e *ExampleXapp) Run() { // Inject own REST handler for testing purpose xapp.Resource.InjectRoute("/ric/v1/testing", e.TestRestHandler, "POST") - go e.messageLoop() xapp.RunWithParams(e, e.waitForSdl) } @@ -159,7 +154,6 @@ func GetMetricsOpts() []xapp.CounterOpts { func NewExampleXapp(rmrReady bool) *ExampleXapp { metrics := GetMetricsOpts() return &ExampleXapp{ - msgChan: make(chan *xapp.RMRParams), stats: xapp.Metric.RegisterCounterGroup(metrics, "ExampleXapp"), rmrReady: rmrReady, waitForSdl: xapp.Config.GetBool("db.waitForSdl"),