root/ossie/trunk/ossie/framework/Application_impl.cpp @ 6434

Revision 6434, 11.6 KB (checked in by balister, 5 years ago)

Add more debug messages so we can see when clients query application settings.

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2004, 2007, 2008 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Core Framework.
6
7OSSIE Core Framework is free software; you can redistribute it and/or modify
8it under the terms of the Lesser GNU General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or
10(at your option) any later version.
11
12OSSIE Core Framework is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15Lesser GNU General Public License for more details.
16
17You should have received a copy of the Lesser GNU General Public License
18along with OSSIE Core Framework; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21****************************************************************************/
22#include <iostream>
23#include <string>
24
25#ifdef HAVE_UNISTD_H
26#include <unistd.h>
27#endif
28
29#ifndef HAVE_UNISTD_H
30#include <process.h>
31#endif
32
33#include "ossie/debug.h"
34#include "ossie/Application_impl.h"
35#include "ossie/ossieSupport.h"
36#include "ossie/portability.h"
37#include "ossie/SADParser.h"
38
39Application_impl::Application_impl (const char *_id,
40const char *_name,
41const char *_profile,
42DEV_SEQ * _devSeq,
43ELEM_SEQ * _implSeq,
44ELEM_SEQ * _ncSeq,
45PROC_ID_SEQ * _pidSeq,
46std::string _waveformName,
47std::vector <ossieSupport::ConnectionInfo *> _connectionData,
48std::vector <ossieSupport::ComponentInfo *> _components,
49CF::Resource_ptr _controller,
50CF::DomainManager::ApplicationSequence *_appseq,
51SADParser *sadParser, CosNaming::NamingContext_ptr wnc)
52{
53    id = _id;
54    appName = _name;
55    sadProfile = _profile;
56    _sadParser = sadParser;
57    connectionData = _connectionData;
58    components = _components;
59    orb = new ossieSupport::ORB();
60    waveformName = _waveformName;
61    waveformContext = wnc;
62
63    appseq = _appseq;
64
65    if (_devSeq != NULL)
66    {
67        this->appComponentDevices = new DEV_SEQ ();
68        this->appComponentDevices->length (_devSeq->length ());
69
70        for (unsigned i = 0; i < _devSeq->length (); i++)
71            (*appComponentDevices)[i] = (*_devSeq)[i];
72    }
73    else
74        this->appComponentDevices = new DEV_SEQ (0);
75
76    if (_implSeq != NULL)
77    {
78        this->appComponentImplementations = new ELEM_SEQ ();
79        this->appComponentImplementations->length (_implSeq->length ());
80
81        for (unsigned int i = 0; i < _implSeq->length (); i++)
82            (*appComponentImplementations)[i] = (*_implSeq)[i];
83    }
84    else
85        this->appComponentImplementations = new ELEM_SEQ (0);
86
87    if (_ncSeq != NULL)
88    {
89        this->appComponentNamingContexts = new ELEM_SEQ ();
90        this->appComponentNamingContexts->length (_ncSeq->length ());
91
92        for (unsigned int i = 0; i < _ncSeq->length (); i++)
93            (*appComponentNamingContexts)[i] = (*_ncSeq)[i];
94    }
95    else
96        this->appComponentNamingContexts = new ELEM_SEQ (0);
97
98    if (_pidSeq != NULL)
99    {
100        this->appComponentProcessIds = new PROC_ID_SEQ ();
101        this->appComponentProcessIds->length (_pidSeq->length ());
102
103        for (unsigned int i = 0; i < _pidSeq->length (); i++)
104            (*appComponentProcessIds)[i] = (*_pidSeq)[i];
105    }
106    else
107        this->appComponentProcessIds = new PROC_ID_SEQ (0);
108
109    this->assemblyController = _controller;
110};
111
112Application_impl::~Application_impl ()
113{
114
115    delete this->appComponentDevices;
116    this->appComponentDevices = NULL;
117
118    delete this->appComponentImplementations;
119    this->appComponentImplementations = NULL;
120
121    delete this->appComponentNamingContexts;
122    this->appComponentNamingContexts = NULL;
123
124    delete this->appComponentProcessIds;
125    this->appComponentProcessIds = NULL;
126};
127
128void
129Application_impl::start ()
130throw (CORBA::SystemException, CF::Resource::StartError)
131{
132    assemblyController->start ();
133}
134
135
136void
137Application_impl::stop ()
138throw (CORBA::SystemException, CF::Resource::StopError)
139{
140    assemblyController->stop ();
141}
142
143
144void Application_impl::configure (const CF::Properties & configProperties) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration)
145{
146}
147
148void Application_impl::query (CF::Properties & configProperties) throw (CORBA::SystemException, CF::UnknownProperties)
149{
150}
151
152
153
154void
155Application_impl::initialize ()
156throw (CORBA::SystemException, CF::LifeCycle::InitializeError)
157{
158    assemblyController->initialize ();
159}
160
161
162CORBA::Object_ptr
163Application_impl::getPort (const char* _id)
164throw (CORBA::SystemException, CF::PortSupplier::UnknownPort)
165{
166    return assemblyController->getPort (_id);
167}
168
169
170void
171Application_impl::runTest (CORBA::ULong _testId, CF::Properties& _props)
172throw (CORBA::SystemException, CF::UnknownProperties, CF::TestableObject::UnknownTest)
173
174{
175    assemblyController->runTest (_testId, _props);
176}
177
178/*
179#ifdef  MS_dotNET
180///\bug It is necessary to have this class because under VC7.1, self-destruct before the CORBA call is complete cannot be implemented
181
182class ApplicationKiller : public ACE_Task_Base
183{
184    protected:
185        Application_impl *local_pApp;
186
187    public:
188        virtual int svc (void)
189        {
190            ossieSupport::sleep(1);
191            delete local_pApp;
192            return 0;
193        }
194
195        void get_address(Application_impl *pApp)
196        {
197            local_pApp = pApp;
198        }
199};
200#endif
201*/
202
203void
204Application_impl::releaseObject ()
205throw (CORBA::SystemException, CF::LifeCycle::ReleaseError)
206{
207    DEBUG(3, Application, "Entering releaseObject");
208
209    // Remove reference for this application from the ApplicationSequence in DomainManager
210    int old_length = appseq->length();
211    int index_found_app = -1;
212    for (int i=0; i<old_length; i++) {
213        if (!strcmp((*(*appseq)[i]->componentNamingContexts())[0].elementId, (*appComponentNamingContexts)[0].elementId)) {
214                index_found_app = i;
215                break;
216        }
217    }
218    if (index_found_app == -1) {
219        std::cout << "The DomainManager's application list is corrupt" << std::endl;
220    } else {
221        for (int i=index_found_app; i<old_length-1; i++) {
222            (*appseq)[i] = (*appseq)[i+1];
223        }
224        appseq->length(old_length-1);
225    }
226
227    std::vector <CF::Device_ptr> registeredDevices;
228
229    assemblyController = CF::Resource::_nil ();
230
231// break all connections in the application
232    for (unsigned int i = 0; i < connectionData.size(); i++) {
233        CF::Port_var port = connectionData[i]->getPort();
234        DEBUG(5, Application, "Disconnecting port: " << connectionData[i]->getID());
235        port->disconnectPort(connectionData[i]->getID());
236    }
237
238    DEBUG(4, Application, "app->releaseObject finished disconnecting ports")
239
240// release all resources
241    //Before releasing the components, all executed processes should be terminated,
242    //all software components unloaded, and all capacities deallocated
243    //search thru all waveform components
244    //if there is a match with the deviceAssignmentSequence, then get a reference to the device
245    //unload and deallocate
246
247    CF::DomainManager_ptr dmnMgr;
248    CORBA::Object_ptr obj = orb->get_object_from_name("DomainName1/DomainManager");
249     dmnMgr = CF::DomainManager::_narrow (obj);
250
251     CF::DomainManager::DeviceManagerSequence* devMgrs;
252     devMgrs = dmnMgr->deviceManagers ();
253     
254     for (unsigned int i=0; i<devMgrs->length(); i++) {
255         CF::DeviceSequence* devices = (*devMgrs)[i]->registeredDevices();
256         for (unsigned int j=0; j<devices->length(); j++) {
257             registeredDevices.push_back((*devices)[j]);
258         }
259     }
260
261     // OLD COMMENT
262//search thru all waveform components
263//if there is a match with the deviceAssignmentSequence, then get a reference to the device
264//unload and deallocate
265
266     for (unsigned int i(0); i < components.size(); ++i) {
267         ossieSupport::ComponentInfo *component = components[i];
268
269         if (component->getDeployedOnResourceFactory()) {
270             ///\todo Write code for resource factory case
271             DEBUG(4, Application, "Releasing component deployed on resource factory.");
272
273         } else if (component->getDeployedOnLoadableDevice()) {
274             ///\todo Write code for loadable device case
275             DEBUG(4, Application, "Releasing component deployed on loadable device.");
276
277         } else if (component->getDeployedOnExecutableDevice()) {
278             DEBUG(4, Application, "Releasing component deployed on executable device.");
279
280             CF::Resource_ptr rsc = components[i]->getResourcePtr();
281             DEBUG(4, Application, "about to release Object");
282
283             rsc->releaseObject ();
284
285             CF::ExecutableDevice_var execDev = CF::ExecutableDevice::_narrow(component->getDevicePtr());
286
287             DEBUG(4, Application, "Unloading: " << component->getLocalFileName());
288             execDev->unload(component->getLocalFileName());
289
290             DEBUG(4, Application, "Terminating PID: " << component->getPID());
291             execDev->terminate (component->getPID());
292             execDev->deallocateCapacity(component->getAllocationCapacities());
293             
294         }
295         
296         DEBUG(4, App, "Finished releasing " << component->getUsageName());
297         
298     }
299     DEBUG(4, Application, "End of component list");
300
301   
302    std::string tc("DomainName1");
303    CosNaming::Name_var rootNc = orb->string_to_CosName(tc.c_str());
304    CORBA::Object_var rootObj = orb->inc->resolve(rootNc);
305    CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::_narrow(rootObj);
306    CosNaming::Name waveformCosName;
307    waveformCosName.length(1);
308    waveformCosName[0].id = CORBA::string_dup(waveformName.c_str());
309
310    DEBUG(4, Application, "Unbinding: " << waveformName);
311
312    rootContext->unbind(waveformCosName);
313
314    DEBUG(4, Application, "Destroying waveform naming context. ");
315
316    waveformContext->destroy();
317
318/*#ifdef  MS_dotNET
319
320/// \bug this alternate structure is necessary to implement functionality that looks like a self-destruct
321
322    ApplicationKiller * handler = new ApplicationKiller;
323
324    handler->get_address(this);
325
326    int result = handler->activate();
327
328#else*/
329
330// this is what the self-destruct should really look like
331///\bug releaseObject code looks like example of what not to do pp492
332//    delete this;
333//#endif
334
335}
336
337
338char *Application_impl::name ()
339throw (CORBA::SystemException)
340{
341    DEBUG(8, Application, "Returning name : " << appName);
342    return CORBA::string_dup(appName.c_str());
343}
344
345
346char *Application_impl::identifier ()
347throw (CORBA::SystemException)
348{
349    DEBUG(8, Application, "Returning identifier : " << id);
350    return CORBA::string_dup(id.c_str());
351}
352
353
354char *Application_impl::profile ()
355throw (CORBA::SystemException)
356{
357    DEBUG(8, Application, "Returning profile : " << sadProfile);
358    return CORBA::string_dup(sadProfile.c_str());
359}
360
361
362PROC_ID_SEQ *
363Application_impl::componentProcessIds ()
364throw (CORBA::SystemException)
365{
366    CF::Application::ComponentProcessIdSequence_var result = new CF::Application::ComponentProcessIdSequence(*appComponentProcessIds);
367    return result._retn();
368    //return this->appComponentProcessIds;
369}
370
371
372ELEM_SEQ *
373Application_impl::componentNamingContexts ()
374throw (CORBA::SystemException)
375{
376    CF::Application::ComponentElementSequence_var result = new ELEM_SEQ(*appComponentNamingContexts);
377    return result._retn();
378    //return this->appComponentNamingContexts;
379}
380
381
382ELEM_SEQ *
383Application_impl::componentImplementations ()
384throw (CORBA::SystemException)
385{
386    CF::Application::ComponentElementSequence_var result = new ELEM_SEQ(*appComponentImplementations);
387    return result._retn();
388    //return this->appComponentImplementations;
389}
390
391
392CF::DeviceAssignmentSequence *
393Application_impl::componentDevices ()throw (CORBA::SystemException)
394{
395    CF::DeviceAssignmentSequence_var result = new CF::DeviceAssignmentSequence(*appComponentDevices);
396    return result._retn();
397    //return this->appComponentDevices;
398}
Note: See TracBrowser for help on using the browser.