Update go.mod
[ric-app/hw-go.git] / hwApp.go
index a02abc9..dc4e4f7 100755 (executable)
--- a/hwApp.go
+++ b/hwApp.go
@@ -27,11 +27,59 @@ import (
 type HWApp struct {
 }
 
+var (
+       A1_POLICY_QUERY      = 20013
+       POLICY_QUERY_PAYLOAD = "{\"policy_type_id\":20000}"
+)
+
+func (e *HWApp) sendPolicyQuery() {
+       xapp.Logger.Info("Invoked method to send  policy query message")
+
+       // prepare and send policy query message over RMR
+       rmrParams := new(xapp.RMRParams)
+       rmrParams.Mtype = A1_POLICY_QUERY // A1_POLICY_QUERY
+       rmrParams.Payload = []byte(POLICY_QUERY_PAYLOAD)
+
+       // send rmr message
+       flg := xapp.Rmr.SendMsg(rmrParams)
+
+       if flg {
+               xapp.Logger.Info("Successfully sent policy query message over RMR")
+       } else {
+               xapp.Logger.Info("Failed to send policy query message over RMR")
+       }
+}
+
 func (e *HWApp) ConfigChangeHandler(f string) {
        xapp.Logger.Info("Config file changed")
 }
 
-func (e *HWApp) Consume(rp *xapp.RMRParams) (err error) {
+func (e *HWApp) xAppStartCB(d interface{}) {
+       xapp.Logger.Info("xApp ready call back received")
+}
+
+func (e *HWApp) 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 {
+       // policy request handler
+       case "A1_POLICY_REQUEST":
+               xapp.Logger.Info("Recived policy instance list")
+
+       // health check request
+       case "RIC_HEALTH_CHECK_REQ":
+               xapp.Logger.Info("Received health check request")
+
+       default:
+               xapp.Logger.Info("Unknown message type '%d', discarding", msg.Mtype)
+       }
+
+       defer func() {
+               xapp.Rmr.Free(msg.Mbuf)
+               msg.Mbuf = nil
+       }()
        return
 }
 
@@ -43,7 +91,14 @@ func (e *HWApp) Run() {
        // set config change listener
        xapp.AddConfigChangeListener(e.ConfigChangeHandler)
 
-       xapp.RunWithParams(e, false)
+       // register callback after xapp ready
+       xapp.SetReadyCB(e.xAppStartCB, true)
+
+       // reading configuration from config file
+       waitForSdl := xapp.Config.GetBool("db.waitForSdl")
+
+       // start xapp
+       xapp.RunWithParams(e, waitForSdl)
 
 }