Example #1
0
int
CApp::run(int argc, char** argv)
{
#if SYSAPI_WIN32
	// record window instance for tray icon, etc
	CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif

	CArch arch;
	arch.init();

	CLog log;
	CEventQueue events;

#if MAC_OS_X_VERSION_10_7
	// dock hide only supported on lion :(
	ProcessSerialNumber psn = { 0, kCurrentProcess };
	GetCurrentProcess(&psn);
	TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
#endif

	// install application in to arch
	appUtil().adoptApp(this);
	
	// HACK: fail by default (saves us setting result in each catch)
	int result = kExitFailed;

	try {
		result = appUtil().run(argc, argv);
	}
	catch (XExitApp& e) {
		// instead of showing a nasty error, just exit with the error code.
		// not sure if i like this behaviour, but it's probably better than 
		// using the exit(int) function!
		result = e.getCode();
	}
	catch (XBase& e) {
		LOG((CLOG_CRIT "Exception: %s\n", e.what()));
	}
	catch (XArch& e) {
		LOG((CLOG_CRIT "Init failed: %s" BYE, e.what().c_str(), argsBase().m_pname));
	}
	catch (std::exception& e) {
		LOG((CLOG_CRIT "Exception: %s\n", e.what()));
	}
	catch (...) {
		LOG((CLOG_CRIT "An unexpected exception occurred.\n"));
	}

	appUtil().beforeAppExit();
	
	return result;
}
Example #2
0
void CMapStringToNode::Serialize(CArch& ar)
{
  string key,val,s1="CMapStringToNode";
  int Count;
  CPNode *pNode=NULL;
  if (ar.IsStoring()) {
    Count = mpn.size();
    ar<<Count<<s1;
    for (ipn=mpn.begin(); ipn!=mpn.end();)  {
      GetNextAssoc(s1, pNode);
      ar<<s1;
      pNode->Serialize(ar);
    }
  }
  else
  {
    ar>>Count>>key;
    if (key !=s1) { throw (-33);  }

    for(int i=0; i<Count; i++) {
      pNode = new CPNode;
      ar>>key;
      pNode->Serialize(ar);
      mpn[key]=pNode;
    }
  }
}
Example #3
0
//-------------------------------------------------------
void CPNodeArraySmall::Serialize(CArch& ar)
{
  string key, s1="CPNodeArray";
  CPNode *pNode;
  int Count,i;
  if (ar.IsStoring()) {
    Count = apn.size();
    ar<<Count<<s1;

    for (i=0; i<Count;i++)  {
      apn[i]->Serialize(ar);
    }
  }
  else
  {
    ar>>Count>>key;
    if (key !=s1)  { throw (-32);  }

    for(i=0; i<Count; i++) {
      pNode = new CPNode;
      pNode->Serialize(ar);
      apn.push_back(pNode);
    }
  }
}
Example #4
0
//-------------------------------------------------------
void CConnectArray::Serialize(CArch& ar)
{
  string key, s1="CConnectArray";
  CSFConnect* pCon;
  int Count,i;
  if (ar.IsStoring()) {
    Count = Acon.size();
    ar<<Count<<s1;

    for (i=0; i<Count;i++)  {
      pCon =Acon[i];   
      pCon->Serialize(ar);
    }
  }
  else
  {
    ar>>Count>>key;
    if (key !=s1) { throw (-8); }

    for(i=0; i<Count; i++) {
      pCon = new CSFConnect("Con");
      pCon->Serialize(ar);
      Acon.push_back(pCon);
    }
  }
}
Example #5
0
void CMapStringToType::Serialize(CArch& ar)
{
  string key, s1="CMapStringToType";
  CSFType *pType;
  int Count;
  if (ar.IsStoring()) {
    Count = mtp.size();
    ar<<Count<<s1;
    itp=mtp.begin();
    for (; itp!=mtp.end();)  {
      GetNextAssoc(s1, *&pType);
      pType->Serialize(ar);
    }
  }
  else
  {
    ar>>Count>>key;
    if (key !=s1)  { throw (-7);  }

    for(int i=0; i<Count; i++) {
      pType = new CSFType;
      pType->Serialize(ar);
      mtp[pType->m_Name]=pType;
    }
  }
}
Example #6
0
int
main(int argc, char** argv) 
{
#if SYSAPI_WIN32
	// record window instance for tray icon, etc
	CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
	
	CArch arch;
	arch.init();

	CLog log;
	CEventQueue events;

	CServerApp app(&events, createTaskBarReceiver);
	return app.run(argc, argv);
}
int
main(int argc, char **argv)
{
#if SYSAPI_WIN32
    // HACK: shouldn't be needed, but logging fails without this.
    CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif

    CArch arch;
    arch.init();

    CLog log;
    log.setFilter(kDEBUG4);

    testing::InitGoogleTest(&argc, argv);

    return RUN_ALL_TESTS();
}
Example #8
0
void CPNode::Serialize(CArch& ar)
{
  if (ar.IsStoring())    {   // storing code here
    ar<<m_PldName; ar<<m_level; ar<<m_NumStringInView;
  }
  else    {                 // loading code here
    ar>>m_PldName; ar>>m_level; ar>>m_NumStringInView;
    m_pSF = new CSF;
  }
  m_pSF->Serialize(ar);
  m_Attr.Serialize(ar);
  m_Children.Serialize(ar); 
}
Example #9
0
//---------------------------------------------------------------
void CSFType::Serialize(CArch& ar)
{
  if (ar.IsStoring())
  {
    ar <<  m_Name <<  m_Lib <<  m_Reg;
  }
  else
  {
    ar >>  m_Name >>  m_Lib >>  m_Reg;
  }
  m_SFVarArray.Serialize(ar);
  Seria(m_ElemArray, ar);
}
Example #10
0
int
main(int argc, char **argv)
{
#if SYSAPI_WIN32
	// record window instance for tray icon, etc
	CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif

	CArch arch;
	arch.init();
	
	CLog log;
	log.setFilter(kDEBUG2);

	string lockFile;
	for (int i = 0; i < argc; i++) {
		if (string(argv[i]).compare("--lock-file") == 0) {
			lockFile = argv[i + 1];
		}
	}

	if (!lockFile.empty()) {
		lock(lockFile);
	}


	testing::InitGoogleTest(&argc, argv);

	int result = RUN_ALL_TESTS();

	if (!lockFile.empty()) {
		unlock(lockFile);
	}

	return result;
}
Example #11
0
//-------------------------------------------------------
void CSFVar::Serialize(CArch& ar)
{
  if (ar.IsStoring())
  {
    ar <<  m_Name;
    ar <<  m_Typ;
    ar <<  m_First << m_Last << m_NumInSF;
  }
  else
  {
    ar >>  m_Name;
    ar >>  m_Typ;
    ar >>  m_First >> m_Last >> m_NumInSF;
  }
}
Example #12
0
//---------------------------------------------------------------
void CSFunction::Serialize(CArch& ar)
{
  if (ar.IsStoring())
  {
    ar <<  m_Typ;
    ar << m_NumInt;
    ar << m_NumOut;
    ar << m_NumInter;
  }
  else
  {
    ar >>  m_Typ;
    ar >> m_NumInt;
    ar >> m_NumOut;
    ar >> m_NumInter;
  }
  Seria(m_Text, ar);
}
Example #13
0
void CSFVarArray::Serialize(CArch& ar)
{
  CSFVar* pVar;
  int i, Count = Avar.size();
  string key, s1="CSFVarArray";
  if (ar.IsStoring()) {
    ar<<Count<<s1;
    for (i=0;i<Count; i++) {
      pVar =Avar[i];
      pVar->Serialize(ar);
    }
  }
  else {
    ar>>Count>>key;
    if (key !=s1)  { throw (-6);  }

    for(int i=0; i<Count; i++) {
      pVar = new CSFVar;
      pVar->Serialize(ar);
      Avar.push_back(pVar);
    }
  }
}
Example #14
0
//--------------------------------------------- void Serialize(CArch&);
void CMapValFrame::Serialize(CArch& ar)
{
  string key,val,s1="CMapValFrame";
  int Count;
  if (ar.IsStoring()) {
    Count = mvf.size();
    ar<<Count<<s1;
    ivf=mvf.begin();
    for (; ivf!=mvf.end();)  {
      s1 = ivf->first; val = ivf->second; ivf++;
      ar << s1 << val;
    }
  }
  else
  {
    ar>>Count>>key;
    if (key !=s1) { throw (-31);  }

    for(int i=0; i<Count; i++) {
      ar >> key >> val;
      mvf[key]=val;
    }
  }
}
Example #15
0
int
CDaemonApp::run(int argc, char** argv)
{
#if SYSAPI_WIN32
	// win32 instance needed for threading, etc.
	CArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
	
	CArch arch;
	arch.init();

	CLog log;
	CEventQueue events;
	m_events = &events;

	bool uninstall = false;
	try
	{
#if SYSAPI_WIN32
		// sends debug messages to visual studio console window.
		log.insert(new CMSWindowsDebugOutputter());
#endif

		// default log level to system setting.
		string logLevel = arch.setting("LogLevel");
		if (logLevel != "")
			log.setFilter(logLevel.c_str());

		bool foreground = false;

		for (int i = 1; i < argc; ++i) {
			string arg(argv[i]);

			if (arg == "/f" || arg == "-f") {
				foreground = true;
			}
#if SYSAPI_WIN32
			else if (arg == "/install") {
				uninstall = true;
				arch.installDaemon();
				return kExitSuccess;
			}
			else if (arg == "/uninstall") {
				arch.uninstallDaemon();
				return kExitSuccess;
			}
#endif
			else {
				stringstream ss;
				ss << "Unrecognized argument: " << arg;
				foregroundError(ss.str().c_str());
				return kExitArgs;
			}
		}

		if (foreground) {
			// run process in foreground instead of daemonizing.
			// useful for debugging.
			mainLoop(false);
		}
		else {
#if SYSAPI_WIN32
			arch.daemonize("Synergy", winMainLoopStatic);
#elif SYSAPI_UNIX
			arch.daemonize("Synergy", unixMainLoopStatic);
#endif
		}

		return kExitSuccess;
	}
	catch (XArch& e) {
		CString message = e.what();
		if (uninstall && (message.find("The service has not been started") != CString::npos)) {
			// TODO: if we're keeping this use error code instead (what is it?!).
			// HACK: this message happens intermittently, not sure where from but
			// it's quite misleading for the user. they thing something has gone
			// horribly wrong, but it's just the service manager reporting a false
			// positive (the service has actually shut down in most cases).
		}
		else {
			foregroundError(message.c_str());
		}
		return kExitFailed;
	}
	catch (std::exception& e) {
		foregroundError(e.what());
		return kExitFailed;
	}
	catch (...) {
		foregroundError("Unrecognized error.");
		return kExitFailed;
	}
}
Example #16
0
//---------------------------------------------------------------
void CSFConnect::Serialize(CArch& ar)
{
  if (ar.IsStoring()) { ar <<  m_Name; }
  else                { ar >>  m_Name; }
  Seria(m_Connect, ar);
}