MojErr IMAccountValidatorApp::open()
{
	MojLogNotice(s_log, _T("%s starting..."), name().data());

	MojErr err = Base::open();
	MojErrCheck(err);

	// open service
	err = m_service.open(ServiceName);
	MojErrCheck(err);
	err = m_service.attach(m_reactor.impl());
	MojErrCheck(err);

	// create and attach service handler
	m_handler.reset(new IMAccountValidatorHandler(&m_service));
	MojAllocCheck(m_handler.get());

	err = m_handler->init(this);
	MojErrCheck(err);

	err = m_service.addCategory(MojLunaService::DefaultCategory, m_handler.get());
	MojErrCheck(err);

	MojLogNotice(s_log, _T("%s started."), name().data());

	return MojErrNone;
}
MojErr IMAccountValidatorApp::close()
{
	MojLogNotice(s_log, _T("%s stopping..."), name().data());

	MojErr err = MojErrNone;
	MojErr errClose = m_service.close();
	MojErrAccumulate(err, errClose);
	errClose = Base::close();
	MojErrAccumulate(err, errClose);

	MojLogNotice(s_log, _T("%s stopped."), name().data());

	return err;
}
Ejemplo n.º 3
0
/*
 * timer callback
 */
gboolean IMServiceHandler::ShutdownCallback(void* data)
{
	assert(data);
	IMServiceHandler* handler = static_cast<IMServiceHandler*>(data);
	handler->m_shutdownCallbackId = 0;

	if (handler->OkToShutdown()) {
		MojLogNotice(IMServiceApp::s_log, "sms service shutting down...");
		IMServiceApp::Shutdown();
	} else {
		MojLogNotice(IMServiceApp::s_log, "sms service shutdown aborted; clients still active");
	}

	return false; // return false to make sure we don't get called again
}
void ContainerManager::Disable()
{
	MojLogTrace(s_log);

	if (!m_enabled) {
		MojLogNotice(s_log, _T("Container Manager already disabled"));
	}

	MojLogNotice(s_log, _T("Disabling Container Manager"));

	m_enabled = false;

	std::for_each(m_containers.begin(), m_containers.end(),
		boost::bind(&ResourceContainer::Disable,
			boost::bind(&ContainerMap::value_type::second, _1)));
}
void ActivityManager::EvictBackgroundActivity(
	boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("Attempting to evict [Activity %llu] from "
		"background queue"), act->GetId());

	ActivityRunQueue::iterator iter;

	for (iter = m_runQueue[RunQueueBackground].begin();
		iter != m_runQueue[RunQueueBackground].end(); ++iter) {
		if (&(*iter) == &(*act)) {
			break;
		}
	}

	if (iter != m_runQueue[RunQueueBackground].end()) {
		act->m_runQueueItem.unlink();
		m_runQueue[RunQueueLongBackground].push_back(*act);
	} else {
		MojLogWarning(s_log, _T("[Activity %llu] Not found on background "
			"queue"), act->GetId());
		throw std::runtime_error("Activity not on background queue");
	}

	CheckReadyQueue();
}
void SmtpAccountEnableCommand::Done()
{
	if(m_msg.get())
		m_msg->replySuccess();

	MojLogNotice(m_log, "successfully enabled SMTP on account %s", AsJsonString(m_client.GetAccountId()).c_str());

	Complete();
}
Ejemplo n.º 7
0
void PowerdProxy::UnregisterRequirements(
	boost::shared_ptr<MasterRequirementManager> master)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("Unregistering requirements"));

	master->UnregisterRequirement("charging", shared_from_this());
	master->UnregisterRequirement("docked", shared_from_this());
	master->UnregisterRequirement("battery", shared_from_this());
}
unsigned int ActivityManager::SetBackgroundConcurrencyLevel(unsigned int level)
{
	MojLogTrace(s_log);
	if (level != UnlimitedBackgroundConcurrency) {
		MojLogNotice(s_log, _T("Background concurrency level set to %u"),
			level);
	} else {
		MojLogNotice(s_log, _T("Background concurrency level set to "
			"Unlimited"));
	}

	unsigned int oldLevel = m_backgroundConcurrencyLevel;
	m_backgroundConcurrencyLevel = level;

	/* May want to run more Background Activities */
	CheckReadyQueue();

	return oldLevel;
}
void ActivityManager::Disable(unsigned mask)
{
	MojLogTrace(s_log);

	if (mask & EXTERNAL_ENABLE) {
		MojLogNotice(s_log, _T("Disabling Activity Manager: External"));
	}

	if (mask & UI_ENABLE) {
		MojLogNotice(s_log, _T("Disabling Activity Manager: Device UI "
			"disabled"));
	}

	if ((mask & ENABLE_MASK) != mask) {
		MojLogWarning(s_log, _T("Unknown bits set in mask in call to Disable: "
			"%x"), mask);
	}

	m_enabled &= ~mask;
}
void ActivityManager::RegisterActivityName(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("[Activity %llu] Registering as %s/\"%s\""),
		act->GetId(), act->GetCreator().GetString().c_str(),
		act->GetName().c_str());

	bool success = m_nameTable.insert(*act).second;
	if (!success) {
		throw std::runtime_error("Activity name is already registed");
	}
}
void ActivityManager::UnregisterActivityName(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("[Activity %llu] Unregistering from %s/\"%s\""),
		act->GetId(), act->GetCreator().GetString().c_str(),
		act->GetName().c_str());

	if (act->m_nameTableItem.is_linked()) {
		act->m_nameTableItem.unlink();
	} else {
		throw std::runtime_error("Activity name is not registered");
	}
}
void ActivityManager::EvictAllBackgroundActivities()
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("Evicting all background Activities to the long "
		"running background Activity list"));

	while (!m_runQueue[RunQueueBackground].empty()) {
		Activity& act = m_runQueue[RunQueueBackground].front();
		act.m_runQueueItem.unlink();
		m_runQueue[RunQueueLongBackground].push_back(act);
	}

	CheckReadyQueue();
}
Ejemplo n.º 13
0
/*
 * Called by each signal handler to indicate the are done processing
 */
void IMServiceHandler::ProcessDone()
{
	m_activeProcesses--;

	if (m_activeProcesses < 0) {
		MojLogError(IMServiceApp::s_log, _T("ProcessDone - active process count is negative!!"));
		m_activeProcesses = 0;
	}

	// remove a current shutdown timer if we have one already
	if (m_shutdownCallbackId) {
		MojLogNotice(IMServiceApp::s_log, "ProcessDone - shutdown delayed");
		g_source_remove(m_shutdownCallbackId);
		m_shutdownCallbackId = 0;
	}

	if (OkToShutdown()) {
		MojLogNotice(IMServiceApp::s_log, "ProcessDone - shutting down in %llu seconds", SHUTDOWN_DELAY_SECONDS);
		m_shutdownCallbackId = g_timeout_add_seconds(SHUTDOWN_DELAY_SECONDS, &ShutdownCallback, this);
	} else {
		MojLogInfo(IMServiceApp::s_log, "ProcessDone - %llu processes still active, accounts still online", m_activeProcesses);
	}
}
void ActivityManager::Enable(unsigned mask)
{
	MojLogTrace(s_log);

	if (mask & EXTERNAL_ENABLE) {
		MojLogNotice(s_log, _T("Enabling Activity Manager: External"));
	}

	if (mask & UI_ENABLE) {
		MojLogNotice(s_log, _T("Enabling Activity Manager: Device UI enabled"));
	}

	if ((mask & ENABLE_MASK) != mask) {
		MojLogWarning(s_log, _T("Unknown bits set in mask in call to Enable: "
			"%x"), mask);
	}

	m_enabled |= (mask & ENABLE_MASK);

	if (IsEnabled()) {
		ScheduleAllActivities();
	}
}
void ActivityManager::RunAllReadyActivities()
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("Running all Activities currently in the Ready "
		"state"));

	while (!m_runQueue[RunQueueReadyInteractive].empty()) {
		RunReadyBackgroundInteractiveActivity(
			m_runQueue[RunQueueReadyInteractive].front());
	}

	while (!m_runQueue[RunQueueReady].empty()) {
		RunReadyBackgroundActivity(m_runQueue[RunQueueReady].front());
	}
}
boost::shared_ptr<Activity> ActivityManager::GetNewActivity(activityId_t id)
{
	MojLogNotice(s_log, _T("[Activity %llu] Forcing allocation"), id);

	ActivityMap::iterator iter = m_activities.find(id);
	if (iter != m_activities.end()) {
		MojLogWarning(s_log, _T("[Activity %llu] Found existing Activity "
			"with same id"), id);
	}

	boost::shared_ptr<Activity> act = boost::make_shared<Activity>(id,
		shared_from_this());
	m_idTable.insert(*act);

	return act;
}
boost::shared_ptr<Activity> ActivityManager::GetNewActivity()
{
	MojLogTrace(s_log);

	boost::shared_ptr<Activity> act;

#ifdef ACTIVITYMANAGER_RANDOM_IDS
	/* Look for unused id */
	while (true) {
		activityId_t id = (activityId_t) ::random();

		/* Activity ID 0 is reserved */
		if (id == 0)
			continue;

		/* Either the searched for element, or the first higher one */
		ActivityIdTable::const_iterator hint = m_idTable.lower_bound(id,
			ActivityIdComp());
		if ((hint == m_idTable.end()) || (hint->GetId() != id)) {
			act = boost::make_shared<Activity>(id, shared_from_this());
			m_idTable.insert(hint, *act);
			break;
		}
	}
#else
	/* Use sequential ID */
	while (true) {
		ActivityIdTable::const_iterator hint = m_idTable.lower_bound(
			m_nextActivityId, ActivityIdComp());
		if ((hint == m_idTable.end()) || (hint->GetId() != m_nextActivityId)) {
			act = boost::make_shared<Activity>(m_nextActivityId++,
				shared_from_this());
			m_idTable.insert(hint, *act);
			break;
		} else {
			m_nextActivityId++;
		}
	}
#endif	/* ACTIVITYMANAGER_RANDOM_IDS */

	MojLogNotice(s_log, _T("[Activity %llu] Allocated"), act->GetId());

	return act;
}
void ActivityManager::ReleaseActivity(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("[Activity %llu] Releasing"), act->GetId());

	EvictQueue(act);

	ActivityMap::iterator iter = m_activities.find(act->GetId());
	if (iter == m_activities.end()) {
		MojLogWarning(s_log, _T("[Activity %llu] Not found in Activity table "
			"while attempting to release"), act->GetId());
	} else {
		if (iter->second == act) {
			m_activities.erase(iter);
		}
	}

	CheckReadyQueue();
}
Ejemplo n.º 19
0
/**
 * Log the json for an incoming IM payload so we can troubleshoot errors in the field in
 * non debug builds.
 *
 * removes "private" data - ie. message body
 */
MojErr IMServiceHandler::privatelogIMMessage(const MojChar* format, MojObject IMObject, const MojChar* messageTextKey) {

	MojString mojStringJson;
	MojString msgText;

	// replace the message body
	// not much we can do about errors here...

	bool found = false;
	MojErr err = IMObject.del(messageTextKey, found);
	MojErrCheck(err);
	if (found) {
		msgText.assign(_T("***IM Body Removed***"));
		IMObject.put(messageTextKey, msgText);
	}

	// log it (non debug)
	IMObject.toJson(mojStringJson);
	MojLogNotice(IMServiceApp::s_log, format, mojStringJson.data());

	return MojErrNone;
}
void ActivityManager::RunReadyBackgroundActivity(
	boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("Attepting to run ready [Activity %llu]"),
		act->GetId());

	ActivityRunQueue::iterator iter;
	for (iter = m_runQueue[RunQueueReady].begin();
		iter != m_runQueue[RunQueueReady].end(); ++iter) {
		if (&(*iter) == &(*act)) {
			break;
		}
	}

	if (iter != m_runQueue[RunQueueReady].end()) {
		RunReadyBackgroundActivity(*iter);
		return;
	}

	for (iter = m_runQueue[RunQueueReadyInteractive].begin();
		iter != m_runQueue[RunQueueReadyInteractive].end(); ++iter) {
		if (&(*iter) == &(*act)) {
			break;
		}
	}

	if (iter != m_runQueue[RunQueueReadyInteractive].end()) {
		RunReadyBackgroundInteractiveActivity(*iter);
		return;
	}

	MojLogWarning(s_log, _T("[Activity %llu] Not found on ready "
		"queue"), act->GetId());
	throw std::runtime_error("Activity not on ready queue");
}
Ejemplo n.º 21
0
void PowerdProxy::ChargerStatusSignal(MojServiceMessage *msg,
	const MojObject& response, MojErr err)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Received charger status signal: %s"),
		MojoObjectJson(response).c_str());

	if (err != MojErrNone) {
		m_chargerStatusSubscribed = false;

		if (MojoCall::IsPermanentFailure(msg, response, err)) {
			MojLogError(s_log, _T("Subscription to charger status signal "
				"experienced an uncorrectable failure: %s"),
				MojoObjectJson(response).c_str());
			m_chargerStatus.reset();
		} else {
			MojLogWarning(s_log, _T("Subscription to charger status signal "
				"failed, resubscribing: %s"),
				MojoObjectJson(response).c_str());
			EnableChargerSignals();
		}
		return;
	}

	if (!m_chargerStatusSubscribed) {
		m_chargerStatusSubscribed = true;
		TriggerChargerStatus();
	}

	/* Not all responses will contain charger information... for example,
	 * the initial subscription result. */
	MojString chargerType;
	bool found = false;
	MojErr err2 = response.get(_T("type"), chargerType, found);
	if (err2) {
		MojLogError(s_log, _T("Error %d retrieving charger type from charger "
			"status signal response"), err2);
		return;
	} else if (found) {
		bool connected;
		found = response.get(_T("connected"), connected);
		if (!found) {
			MojLogWarning(s_log, _T("Charger type \"%s\" found, but not "
				"whether or not it's connected"), chargerType.data());
			return;
		}

		if (chargerType == "usb") {
			m_usbChargerConnected = connected;
		} else if (chargerType == "inductive") {
			m_inductiveChargerConnected = connected;
		} else {
			MojLogWarning(s_log, _T("Unknown charger type \"%s\" found"),
				chargerType.data());
			return;
		}

		found = false;
		MojString name;
		err2 = response.get(_T("name"), name, found);
		if (err2) {
			MojLogError(s_log, _T("Error %d retrieving the specific "
				"name of charger of type \"%s\""), err2, chargerType.data());
		} else if (found) {
			if (name == "puck") {
				m_onPuck = connected;
			}
		}

		if (m_onPuck) {
			if (!m_dockedRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is now docked"));
				m_dockedRequirementCore->Met();
				std::for_each(m_dockedRequirements.begin(),
					m_dockedRequirements.end(),
					boost::mem_fn(&Requirement::Met));
			}
		} else {
			if (m_dockedRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is no longer docked"));
				m_dockedRequirementCore->Unmet();
				std::for_each(m_dockedRequirements.begin(),
					m_dockedRequirements.end(),
					boost::mem_fn(&Requirement::Unmet));
			}
		}

		if (m_inductiveChargerConnected || m_usbChargerConnected) {
			if (!m_chargingRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is now charging"));
				m_chargingRequirementCore->Met();
				std::for_each(m_chargingRequirements.begin(),
					m_chargingRequirements.end(),
					boost::mem_fn(&Requirement::Met));
			}
		} else {
			if (m_chargingRequirementCore->IsMet()) {
				MojLogNotice(s_log, _T("Device is no longer charging"));
				m_chargingRequirementCore->Unmet();
				std::for_each(m_chargingRequirements.begin(),
					m_chargingRequirements.end(),
					boost::mem_fn(&Requirement::Unmet));
			}
		}
	}
}