Exemplo n.º 1
0
int main( int argc, char *argv[] )
{
	IComponentManager *mgr = getComponentManager();
	ErrorCode result;
	
	result = mgr->LoadLibrary( "libfooservice.so" );

	if ( result != kNoError )
	{
		LOG_WARN( "Failed to fail library %d", result );
		return 0;
	}
	
	SmartPtr<IFooService> service = doGetService( "FooService", &result );
	
	if ( result == kNoError )
		service->Run();
	else
		LOG_WARN( "Failed to get service %d", result );
	
	SmartPtr<IFoo> foo = doCreateInstance( "FooFactory", &result );
	
	if ( result == kNoError )
		foo->Run();
	else
		LOG_WARN( "Failed to get service %d", result );
		
	return 0;
}
Exemplo n.º 2
0
  SensAlgorithmExitStatus SensApplication::Run()
  {
    DBG_START_METH("SensApplication::Run", dbg_verbosity);

    SensAlgorithmExitStatus retval = SOLVE_SUCCESS;

    bool sens_internal_abort, redhess_internal_abort;
    Options()->GetBoolValue("sens_internal_abort", sens_internal_abort, "");
    Options()->GetBoolValue("redhess_internal_abort", redhess_internal_abort, "");
    if (run_sens_ && sens_internal_abort) {
      jnlst_->Printf(J_WARNING, J_MAIN, "\n\t--------------= Warning =--------------\nInternal abort has been called for the sensitivity calculations.\n");
    }
    if (compute_red_hessian_ && redhess_internal_abort) {
      jnlst_->Printf(J_WARNING, J_MAIN, "\n\t--------------= Warning =--------------\nInternal abort has been called for the sensitivity calculations.\n");
    }

    SolverReturn status = AppReturn2SolverReturn(ipopt_retval_);

    // Check for perturbation of primal dual system
    Number max_pdpert;
    if (ipopt_retval_==0 || ipopt_retval_==1) { // otherwise, the values might not be available
      Options()->GetNumericValue("sens_max_pdpert", max_pdpert, "");
      Number pdpert_x, pdpert_s, pdpert_c, pdpert_d;
      ip_data_->getPDPert(pdpert_x, pdpert_s, pdpert_c, pdpert_d);
      if (Max(pdpert_x, pdpert_s, pdpert_c, pdpert_d)>max_pdpert) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\n\t--------------= Warning =--------------\nInertia correction of primal dual system is too large for meaningful sIPOPT results.\n"
		       "\t... aborting computation.\n"
		       "Set option sens_max_pdpert to a higher value (current: %f) to run sIPOPT algorithm anyway\n", max_pdpert);
	sens_internal_abort = true;
	redhess_internal_abort = true;
      }
    }


    if (compute_red_hessian_ && !redhess_internal_abort) {
      SmartPtr<SensBuilder> schur_builder = new SensBuilder();
      const std::string prefix = ""; // I should be getting this somewhere else...
      SmartPtr<ReducedHessianCalculator> red_hess_calc = schur_builder->BuildRedHessCalc(*jnlst_,
											 *options_,
											 prefix,
											 *ip_nlp_,
											 *ip_data_,
											 *ip_cq_,
											 *pd_solver_);

      red_hess_calc->ComputeReducedHessian();
    }

    if (run_sens_ && n_sens_steps_>0 && !sens_internal_abort) {
      SmartPtr<SensBuilder> schur_builder = new SensBuilder();
      const std::string prefix = ""; // I should be getting this somewhere else...
      SmartPtr<SensAlgorithm> controller = schur_builder->BuildSensAlg(*jnlst_,
								       *options_,
								       prefix,
								       *ip_nlp_,
								       *ip_data_,
								       *ip_cq_,
								       *pd_solver_);

      retval = controller->Run();
    }
    else if (run_sens_) {
      if (n_sens_steps_<=0) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\n"
		       "The run_sens option was set to true, but the specified\n"
		       "number of sensitivity steps was set to zero.\n"
		       "Computation is aborted.\n\n");
      }
    }


    if (IsValid(ip_data_->curr()) && IsValid(ip_data_->curr()->x())) {
      SmartPtr<const Vector> c;
      SmartPtr<const Vector> d;
      SmartPtr<const Vector> zL;
      SmartPtr<const Vector> zU;
      SmartPtr<const Vector> yc;
      SmartPtr<const Vector> yd;
      Number obj = 0.;

      switch (status) {
      case SUCCESS:
	/*c = ip_cq_->curr_c();
	  d = ip_cq_->curr_d();
	  obj = ip_cq_->curr_f();
	  zL = ip_data_->curr()->z_L();
	  zU = ip_data_->curr()->z_U();
	  yc = ip_data_->curr()->y_c();
	  yd = ip_data_->curr()->y_d();*/
      case MAXITER_EXCEEDED:
      case STOP_AT_TINY_STEP:
      case STOP_AT_ACCEPTABLE_POINT:
      case LOCAL_INFEASIBILITY:
      case USER_REQUESTED_STOP:
      case FEASIBLE_POINT_FOUND:
      case DIVERGING_ITERATES:
      case RESTORATION_FAILURE:
      case ERROR_IN_STEP_COMPUTATION:
	c = ip_cq_->curr_c();
	d = ip_cq_->curr_d();
	obj = ip_cq_->curr_f();
	zL = ip_data_->curr()->z_L();
	zU = ip_data_->curr()->z_U();
	yc = ip_data_->curr()->y_c();
	yd = ip_data_->curr()->y_d();
	break;
      default:
	SmartPtr<Vector> tmp = ip_data_->curr()->y_c()->MakeNew();
	tmp->Set(0.);
	c = ConstPtr(tmp);
	yc = ConstPtr(tmp);
	tmp = ip_data_->curr()->y_d()->MakeNew();
	tmp->Set(0.);
	d = ConstPtr(tmp);
	yd = ConstPtr(tmp);
	tmp = ip_data_->curr()->z_L()->MakeNew();
	tmp->Set(0.);
	zL = ConstPtr(tmp);
	tmp = ip_data_->curr()->z_U()->MakeNew();
	tmp->Set(0.);
	zU = ConstPtr(tmp);
      }

      if (compute_red_hessian_ && redhess_internal_abort) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\nReduced hessian was not computed "
		       "because an error occured.\n"
		       "See exception message above for details.\n\n");
      }
      if (run_sens_ && sens_internal_abort) {
	jnlst_->Printf(J_WARNING, J_MAIN, "\nsIPOPT was not called "
		       "because an error occured.\n"
		       "See exception message above for details.\n\n");
      }

      ip_nlp_->FinalizeSolution(status,
				*ip_data_->curr()->x(),
				*zL, *zU, *c, *d, *yc, *yd,
				obj, GetRawPtr(ip_data_), GetRawPtr(ip_cq_));
    }
    return retval;
  }
HRESULT StartGraph(HWND window)
{
    HRESULT hr = S_OK;

    const DWORD BUFFER_SIZE = MAX_PATH * MAX_VIDEO_STREAMS;

    MultiSelectFileList<BUFFER_SIZE> selectList;

    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize         = sizeof(OPENFILENAME);
    ofn.hwndOwner           = g_hWnd;
    ofn.lpstrFilter         = TEXT("Video Files (.AVI, .MPG, .MPEG, .VOB, .WMV)\0*.AVI;*.MPG;*.MPEG;*.VOB;*.WMV\0") 
                              TEXT("All Files (*.*)\0*.*\0\0");
    ofn.nFilterIndex        = 1;
    ofn.lpstrFile           = selectList.BufferPtr();
    ofn.nMaxFile            = selectList.BufferSizeCch();
    ofn.lpstrTitle          = TEXT("Select a video file to play...");
    ofn.Flags               = OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_EXPLORER;
    ofn.lpstrDefExt         = TEXT("AVI");
    
    // Launch the Open File dialog.
	DWORD result = GetOpenFileName(&ofn);

    // Check for errors.
    if (CommDlgExtendedError() != 0)
    {

        // NOTE: For mult-selection, CommDlgExtendedError can return FNERR_BUFFERTOOSMALL even when
        // GetOpenFileName returns TRUE.

        MessageBox(NULL, TEXT( "Could not open files." ), NULL, MB_OK | MB_ICONERROR);
        return E_FAIL;
    }
    else if (!result)
    {
        // The user cancelled. (No error occurred.)
        return S_OK;
    }

    FAIL_RET(hr = selectList.ParseBuffer());

    // Clear all DirectShow interfaces (COM smart pointers)
    g_compositor            = NULL;
    g_windowlessControl     = NULL;
    g_mediaControl          = NULL;
    g_filter                = NULL;
    g_graph                 = NULL;

    // Create the Filter Graph Manager.
    FAIL_RET( CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&g_graph) );

    // Configure the VMR-9.
    FAIL_RET( ConfigureVMR9(window) );

    // Render every file that the user selected.
    for (DWORD i = 0; i < MAX_VIDEO_STREAMS; i++)
    {
        TCHAR *pFileName = NULL;

        FAIL_RET(hr = selectList.Next(&pFileName));
        if (hr == S_FALSE)
        {
            hr = S_OK;
            break;
        }

		hr = g_graph->RenderFile( pFileName, NULL );

        CoTaskMemFree(pFileName);

        FAIL_RET(hr);

	}

    // Run the graph.

    FAIL_RET( g_graph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&g_mediaControl)) );

    FAIL_RET( g_mediaControl->Run() );

    return hr;
}
HRESULT StartGraph(HWND window)
{
    // Clear DirectShow interfaces (COM smart pointers)
    CloseGraph(window);

    SmartPtr<IVMRFilterConfig9> filterConfig;


    BSTR path = GetMoviePath();
    if( ! path )
    {
        return E_FAIL;
    }

    HRESULT hr;
    
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&g_graph);

    if (SUCCEEDED(hr))
    {
        hr = CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&g_filter);
    }

    if (SUCCEEDED(hr))
    {
        hr = g_filter->QueryInterface(IID_IVMRFilterConfig9, reinterpret_cast<void**>(&filterConfig));
    }

    if (SUCCEEDED(hr))
    {
        hr = filterConfig->SetRenderingMode( VMR9Mode_Renderless );

    }

    if (SUCCEEDED(hr))
    {
        hr = filterConfig->SetNumberOfStreams(2);

    }

    if (SUCCEEDED(hr))
    {
        hr = SetAllocatorPresenter( g_filter, window );
    }

    if (SUCCEEDED(hr))
    {
        hr = g_graph->AddFilter(g_filter, L"Video Mixing Renderer 9");
    }

    if (SUCCEEDED(hr))
    {
        hr = g_graph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&g_mediaControl));
    }

    if (SUCCEEDED(hr))
    {
        hr = g_graph->RenderFile( path, NULL );
    }

    if (SUCCEEDED(hr))
    {
        hr = g_mediaControl->Run();
    }

    SysFreeString(path);

    return hr;
}