Revision of copyright
[ric-app/kpimon.git] / src / KPI-Message-Handler / KPIMessageHandler.cc
1 /*\r
2 ==================================================================================\r
3 \r
4         Copyright (c) 2018-2019 SAMSUNG Intellectual Property.\r
5 \r
6    Licensed under the Apache License, Version 2.0 (the "License");\r
7    you may not use this file except in compliance with the License.\r
8    You may obtain a copy of the License at\r
9 \r
10        http://www.apache.org/licenses/LICENSE-2.0\r
11 \r
12    Unless required by applicable law or agreed to in writing, software\r
13    distributed under the License is distributed on an "AS IS" BASIS,\r
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15    See the License for the specific language governing permissions and\r
16    limitations under the License.\r
17 ==================================================================================\r
18 */\r
19 \r
20 \r
21 #include "KPIMessageHandler.h"\r
22 \r
23 kpi_msg_handler::kpi_msg_handler()\r
24 {       \r
25   m_access = std::make_unique<std::mutex>();\r
26 }\r
27 \r
28 // Decodes the CuCpResourceStatusReport present in the RIC Indication Message and Calls the method to Update the content in the DB.\r
29 bool kpi_msg_handler::operator()(redisContext *redis_context, unsigned char *msg_ref, size_t msg_size)\r
30 {\r
31   \r
32   bool res = true;\r
33   \r
34   std::lock_guard<std::mutex> lck(*(m_access.get()));\r
35 \r
36   CuCpResourceStatusReport_t *cucp_resource_status_rcv = 0;\r
37 \r
38   /* Decode */\r
39   asn_dec_rval_t dec_res = asn_decode(0,ATS_ALIGNED_BASIC_PER, &asn_DEF_CuCpResourceStatusReport, (void **)&cucp_resource_status_rcv, msg_ref, msg_size);\r
40 \r
41   if (dec_res.code == RC_OK){\r
42           mdclog_write(MDCLOG_INFO, "Processing CuCpResourceStatusReport message\n");\r
43           res = true;\r
44   }\r
45   else{\r
46     mdclog_write(MDCLOG_ERR, "Error :: %s, %d :: Could not decode CuCpResourceStatusReport of size %lu bytes \n", __FILE__, __LINE__, msg_size);\r
47     res = false;\r
48   }\r
49 \r
50   if (res){\r
51     \r
52     //std::cout <<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;\r
53     //xer_fprint(stdout,  &asn_DEF_CuCpResourceStatusReport, cucp_resource_status_rcv);\r
54     //std::cout <<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << std::endl;\r
55 \r
56     // Add our get field function for Custom message\r
57     res = kpi_report.get_fields(cucp_resource_status_rcv, kpi_data);\r
58     if (!res){\r
59       mdclog_write(MDCLOG_ERR, "Error :: %s, %d :: could not get  fields from CuCpResourceStatusReport. Reason = %s\n", __FILE__, __LINE__, kpi_report.get_error().c_str());\r
60     }\r
61   }\r
62 \r
63   kpi_db_res.UpdateDB(redis_context,&kpi_data);\r
64 \r
65   ASN_STRUCT_FREE(asn_DEF_CuCpResourceStatusReport, cucp_resource_status_rcv);\r
66   return res;\r
67   \r
68 }\r
69 \r
70 void kpi_msg_handler::clear()\r
71 {\r
72   std::lock_guard<std::mutex> lck(*(m_access.get()));\r
73 }