Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions source/bulkdata/reportprofiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,11 @@ void ReportProfiles_ProcessReportProfilesBlob(cJSON *profiles_root, bool rprofil

if(!strcmp(existingProfileHash, profileEntry->hash))
{
T2Debug("%s Profile hash for %s is same as previous profile, ignore processing config\n", __FUNCTION__, profileName);
if(!isProfileSchedulerRunning(profileName))
{
T2Warning("Profile %s scheduler not running, re-enabling\n", profileName);
enableProfile(profileName);
}
Comment thread
tabbas651 marked this conversation as resolved.
free(existingProfileHash);
continue;
}
Expand Down Expand Up @@ -1404,7 +1408,11 @@ int __ReportProfiles_ProcessReportProfilesMsgPackBlob(void *msgpack, bool checkP
{
if(0 == msgpack_strcmp(hashObj, existingProfileHash))
{
T2Info("Profile %s with %s hash already exist \n", profileName, existingProfileHash);
if(!isProfileSchedulerRunning(profileName))
{
T2Warning("Profile %s scheduler not running, re-enabling\n", profileName);
enableProfile(profileName);
}
Comment thread
tabbas651 marked this conversation as resolved.
free(profileName);
free(existingProfileHash);
continue;
Expand Down
27 changes: 27 additions & 0 deletions source/scheduler/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <pthread.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
Expand Down Expand Up @@ -430,6 +431,32 @@ T2ERROR SendInterruptToTimeoutThread(char* profileName)
return T2ERROR_SUCCESS;
}

bool isProfileSchedulerRunning(const char* profileName)
{
if(!sc_initialized || profileName == NULL || profileList == NULL)
return false;

if(pthread_mutex_lock(&scMutex) != 0)
return false;

size_t index = 0;
for(; index < profileList->count; ++index)
{
SchedulerProfile *tProfile = (SchedulerProfile *)Vector_At(profileList, index);
if(tProfile == NULL || tProfile->name == NULL)
continue;
if(strcmp(tProfile->name, profileName) == 0)
{
/* pthread_kill with signal 0 checks if the thread is still alive */
bool running = (pthread_kill(tProfile->tId, 0) == 0);
pthread_mutex_unlock(&scMutex);
return running;
}
}
pthread_mutex_unlock(&scMutex);
return false;
}

T2ERROR initScheduler(TimeoutNotificationCB notificationCb, ActivationTimeoutCB activationCB, NotifySchedulerstartCB notifyschedulerCB)
{
T2Debug("%s ++in\n", __FUNCTION__);
Expand Down
2 changes: 2 additions & 0 deletions source/scheduler/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ T2ERROR unregisterProfileFromScheduler(const char* profileName);

T2ERROR SendInterruptToTimeoutThread(char* profileName);

bool isProfileSchedulerRunning(const char* profileName);
Comment thread
tabbas651 marked this conversation as resolved.

bool get_retainseekmap();

void set_retainseekmap(bool value);
Expand Down
7 changes: 7 additions & 0 deletions source/test/bulkdata/SchedulerMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,11 @@ int getLapsedTime(struct timespec *result, struct timespec *x, struct timespec *
return 0;
}

bool isProfileSchedulerRunning(const char* profileName)
{
if (g_schedulerMock)
return g_schedulerMock->isProfileSchedulerRunning(profileName);
return false;
}

} // extern "C"
1 change: 1 addition & 0 deletions source/test/bulkdata/SchedulerMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SchedulerMock
MOCK_METHOD(bool, get_retainseekmap, (), ());
MOCK_METHOD(void, set_retainseekmap, (bool value), ());
MOCK_METHOD(int, getLapsedTime, (struct timespec *result, struct timespec *x, struct timespec *y), ());
MOCK_METHOD(bool, isProfileSchedulerRunning, (const char* profileName), ());
};

extern SchedulerMock* g_schedulerMock;
Expand Down
38 changes: 38 additions & 0 deletions source/test/scheduler/schedulerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,44 @@ TEST(UNREGISTERPROFILEFROMSCHEDULER, ALREADY_REMOVED)
EXPECT_EQ(T2ERROR_FAILURE, unregisterProfileFromScheduler("REMOVEME"));
uninitScheduler();
}
TEST(ISPROFILESCHEDULERRUNNING, NOT_INITIALIZED)
{
uninitScheduler();
EXPECT_FALSE(isProfileSchedulerRunning("RDKB_Profile"));
}

TEST(ISPROFILESCHEDULERRUNNING, NULL_PROFILE)
{
initScheduler((TimeoutNotificationCB)ReportProfiles_ToutCb, (ActivationTimeoutCB)ReportProfiles_ActivationToutCb, (NotifySchedulerstartCB)NotifySchedulerstartCb);
EXPECT_FALSE(isProfileSchedulerRunning(NULL));
uninitScheduler();
}

TEST(ISPROFILESCHEDULERRUNNING, PROFILE_NOT_FOUND)
{
initScheduler((TimeoutNotificationCB)ReportProfiles_ToutCb, (ActivationTimeoutCB)ReportProfiles_ActivationToutCb, (NotifySchedulerstartCB)NotifySchedulerstartCb);
EXPECT_FALSE(isProfileSchedulerRunning("NONEXISTENT"));
uninitScheduler();
}

TEST(ISPROFILESCHEDULERRUNNING, RUNNING_PROFILE)
{
initScheduler((TimeoutNotificationCB)ReportProfiles_ToutCb, (ActivationTimeoutCB)ReportProfiles_ActivationToutCb, (NotifySchedulerstartCB)NotifySchedulerstartCb);
registerProfileWithScheduler("RUNNING_TEST", 300, 3600, false, true, false, 0, "0001-01-01T00:00:00Z");
EXPECT_TRUE(isProfileSchedulerRunning("RUNNING_TEST"));
unregisterProfileFromScheduler("RUNNING_TEST");
uninitScheduler();
}

TEST(ISPROFILESCHEDULERRUNNING, AFTER_UNREGISTER)
{
initScheduler((TimeoutNotificationCB)ReportProfiles_ToutCb, (ActivationTimeoutCB)ReportProfiles_ActivationToutCb, (NotifySchedulerstartCB)NotifySchedulerstartCb);
registerProfileWithScheduler("UNREG_TEST", 300, 3600, false, true, false, 0, "0001-01-01T00:00:00Z");
unregisterProfileFromScheduler("UNREG_TEST");
EXPECT_FALSE(isProfileSchedulerRunning("UNREG_TEST"));
uninitScheduler();
}

#ifdef GTEST_ENABLE
extern "C"
{
Expand Down
Loading