lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 |
|
| 2 | #include "cwmp/periodic.h"
|
| 3 | #include "cwmp/cwmp.h"
|
| 4 | #include "cwmp/log.h"
|
| 5 | #include "soft_timer.h"
|
| 6 |
|
| 7 | extern cwmp_t *g_cwmp;
|
| 8 |
|
| 9 | #define PERIODIC_INFORM_TIMER (30)
|
| 10 |
|
| 11 | #define PERIODIC_ENABLE_INI_TAG "periodic:enable"
|
| 12 | #define PERIODIC_INTERVAL_INI_TAG "periodic:interval"
|
| 13 |
|
| 14 |
|
| 15 | static void *periodic_inform_timer(void *arg)
|
| 16 | {
|
| 17 | FUNCTION_TRACE();
|
| 18 |
|
| 19 | cwmp_t *cwmp = g_cwmp;
|
| 20 |
|
| 21 | cwmp_log_info("push begin");
|
| 22 |
|
| 23 | cwmp->new_request = CWMP_YES;
|
| 24 | cwmp_event_set_value(g_cwmp, INFORM_PERIODIC, 1, 0, 0, 0, 0);
|
| 25 |
|
| 26 | cwmp_log_info("push ok");
|
| 27 |
|
| 28 | return NULL;
|
| 29 | }
|
| 30 |
|
| 31 |
|
| 32 | int cwmp_reset_periodic_inform(cwmp_t * cwmp)
|
| 33 | {
|
| 34 | long result = 0;
|
| 35 |
|
| 36 | periodic_info_st * pperiodic = &(cwmp->periodic_info);
|
| 37 |
|
| 38 | cwmp_log_info("Enable is: %d, interval:%d", pperiodic->PeriodicInformEnable, pperiodic->PeriodicInformInterval);
|
| 39 |
|
| 40 | if(pperiodic->PeriodicInformEnable)
|
| 41 | {
|
| 42 |
|
| 43 | sc_timer_delete(PERIODIC_INFORM_TIMER);
|
| 44 | result = sc_timer_create(PERIODIC_INFORM_TIMER, 0, pperiodic->PeriodicInformInterval*1000, periodic_inform_timer, &cwmp);
|
| 45 | }
|
| 46 |
|
| 47 | return result;
|
| 48 | }
|
| 49 |
|
| 50 |
|
| 51 | int cwmp_clean_periodic_inform(cwmp_t * cwmp)
|
| 52 | {
|
| 53 | sc_timer_delete(PERIODIC_INFORM_TIMER);
|
| 54 |
|
| 55 | return CWMP_OK;
|
| 56 | }
|
| 57 |
|
| 58 |
|
| 59 | int get_periodic_info_enable()
|
| 60 | {
|
| 61 | int cwmp_enable = 0;
|
| 62 | cwmp_enable = cwmp_conf_get_int(PERIODIC_ENABLE_INI_TAG);
|
| 63 |
|
| 64 | if(0 == cwmp_enable)
|
| 65 | {
|
| 66 | return 0;
|
| 67 | }
|
| 68 | else
|
| 69 | {
|
| 70 | return 1;
|
| 71 | }
|
| 72 |
|
| 73 | }
|
| 74 |
|
| 75 |
|
| 76 | int get_periodic_info_interval()
|
| 77 | {
|
| 78 | int interval = 0;
|
| 79 |
|
| 80 | interval = cwmp_conf_get_int(PERIODIC_INTERVAL_INI_TAG);
|
| 81 |
|
| 82 | if(0 != interval)
|
| 83 | {
|
| 84 | return interval;
|
| 85 | }
|
| 86 | else
|
| 87 | {
|
| 88 | return 60;
|
| 89 | }
|
| 90 | }
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 | int set_periodic_info_enable(const char* value)
|
| 95 | {
|
| 96 | return cwmp_conf_set(PERIODIC_ENABLE_INI_TAG, value);
|
| 97 | }
|
| 98 |
|
| 99 |
|
| 100 | int set_periodic_info_interval(const char* value)
|
| 101 | {
|
| 102 | return cwmp_conf_set(PERIODIC_INTERVAL_INI_TAG, value);
|
| 103 | }
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 | int update_periodic_info_enable(cwmp_t* cwmp)
|
| 108 | {
|
| 109 | periodic_info_st *pperiodic_info = &(cwmp->periodic_info);
|
| 110 |
|
| 111 | pperiodic_info->PeriodicInformEnable = get_periodic_info_enable();
|
| 112 |
|
| 113 | return CWMP_OK;
|
| 114 | }
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 | int update_periodic_info_interval(cwmp_t* cwmp)
|
| 119 | {
|
| 120 | periodic_info_st *pperiodic_info = &(cwmp->periodic_info);
|
| 121 |
|
| 122 | pperiodic_info->PeriodicInformInterval = get_periodic_info_interval();
|
| 123 |
|
| 124 | return CWMP_OK;
|
| 125 | }
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 | int ini_periodic_info(cwmp_t* cwmp)
|
| 130 | {
|
| 131 | update_periodic_info_enable(cwmp);
|
| 132 |
|
| 133 | update_periodic_info_interval(cwmp);
|
| 134 |
|
| 135 | return CWMP_OK;
|
| 136 | }
|
| 137 |
|
| 138 |
|
| 139 |
|