22 #ifndef SERVICE_IMPL_H 23 #define SERVICE_IMPL_H 32 #include "ossie/ossieSupport.h" 33 #include "ossie/debug.h" 34 #include "ossie/CorbaUtils.h" 35 #include "ossie/logging/loghelpers.h" 36 #include "ossie/Containers.h" 37 #include "ossie/Autocomplete.h" 46 static void start_service(T** servPtr,
struct sigaction sa,
int argc,
char* argv[]) {
49 const char* logging_config_uri = 0;
51 std::string logcfg_uri(
"");
52 std::string dpath(
"");
53 std::string sname(
"");
55 std::map<std::string, char*> execparams;
57 for (
int i = 0; i < argc; i++) {
59 if (strcmp(
"DEVICE_MGR_IOR", argv[i]) == 0) {
60 devMgr_ior = argv[++i];
61 }
else if (strcmp(
"SERVICE_NAME", argv[i]) == 0) {
64 }
else if (strcmp(
"LOGGING_CONFIG_URI", argv[i]) == 0) {
65 logging_config_uri = argv[++i];
66 }
else if (strcmp(
"DEBUG_LEVEL", argv[i]) == 0) {
67 debug_level = atoi(argv[++i]);
68 }
else if (strcmp(
"DOM_PATH", argv[i]) == 0) {
71 std::string paramName = argv[i];
72 execparams[paramName] = argv[++i];
79 ossie::corba::CorbaInit(argc, argv);
82 if ( logging_config_uri ) logcfg_uri=logging_config_uri;
85 ossie::logging::ResourceCtxPtr ctx(
new ossie::logging::ServiceCtx( sname, dpath ) );
88 ossie::logging::Configure(logcfg_uri, debug_level, ctx);
90 if ((devMgr_ior == 0) || (name == 0)) {
91 LOG_FATAL(
Service_impl,
"Per SCA specification, DEVICE_MGR_IOR and SERVICE_NAME must be provided");
95 LOG_DEBUG(
Service_impl,
"Name = " << name <<
" IOR = " << devMgr_ior)
98 if( sigaction( SIGINT, &sa, NULL ) == -1 ) {
104 if( sigaction( SIGQUIT, &sa, NULL ) == -1 ) {
110 if( sigaction( SIGTERM, &sa, NULL ) == -1 ) {
118 signal(SIGINT, SIG_IGN);
120 *servPtr =
new T(devMgr_ior, name);
121 PortableServer::ObjectId_var oid = ossie::corba::RootPOA()->activate_object(*servPtr);
122 (*servPtr)->resolveDeviceManager();
123 (*servPtr)->registerServiceWithDevMgr();
125 (*servPtr)->terminateService();
126 (*servPtr)->_remove_ref();
128 ossie::corba::OrbShutdown(
true);
132 static std::string
getLogConfig(
const char* devmgr_ior,
const char* log_config, std::string& devmgr_label) {
135 std::string _local_logconfig_path;
138 CF::DeviceManager_ptr _devMgr_ptr = CF::DeviceManager::_nil();
139 CORBA::Object_var _devMgr_obj = ossie::corba::Orb()->string_to_object(devmgr_ior);
140 if (CORBA::is_nil(_devMgr_obj)) {
141 std::cout <<
"ERROR:Service_impl:getLogConfig - Invalid device manager IOR: " << devmgr_ior << std::endl;
142 return _local_logconfig_path;
145 _devMgr_ptr = CF::DeviceManager::_narrow(_devMgr_obj);
146 if (CORBA::is_nil(_devMgr_ptr)) {
147 std::cout <<
"ERROR:Service_impl:getLogConfig - Could not narrow device manager IOR: " << devmgr_ior << std::endl;
148 return _local_logconfig_path;
152 devmgr_label = _devMgr_ptr->label();
155 CF::File_var logFile;
156 CF::OctetSequence_var logFileData;
158 logFile = _devMgr_ptr->fileSys()->open(log_config,
true);
159 unsigned int logFileSize = logFile->sizeOf();
160 logFile->read(logFileData, logFileSize);
162 std::cout <<
"ERROR:Service_impl:getLogConfig - Could not copy file to local memory. File name: " << log_config << std::endl;
163 return _local_logconfig_path;
167 std::string tmp_log_config = log_config;
168 std::string::size_type slash_loc = tmp_log_config.find_last_of(
"/");
169 if (slash_loc != std::string::npos) {
170 _local_logconfig_path = tmp_log_config.substr(slash_loc + 1);
174 std::fstream _local_logconfig;
175 std::ios_base::openmode _local_logconfig_mode = std::ios::in | std::ios::out | std::ios::trunc;
177 _local_logconfig.open(_local_logconfig_path.c_str(), _local_logconfig_mode);
178 if (!_local_logconfig.is_open()) {
179 std::cout <<
"ERROR:Service_impl:getLogConfig - Could not open log file on local system. File name: " << _local_logconfig_path << std::endl;
183 _local_logconfig.write((
const char*)logFileData->get_buffer(), logFileData->length());
184 if (_local_logconfig.fail()) {
185 std::cout <<
"ERROR:Service_impl:getLogConfig - Could not write log file on local system. File name: " << _local_logconfig_path << std::endl;
188 _local_logconfig.close();
190 std::cout <<
"ERROR:Service_impl:getLogConfig - Could not copy file to local system. File name: " << _local_logconfig_path << std::endl;
191 _local_logconfig_path.clear();
192 return _local_logconfig_path;
195 return _local_logconfig_path;
228 virtual void halt ();
234 return this->_devMgr;
238 return this->_domMgr;
247 void initResources(
char*,
char*);
248 redhawk::DeviceManagerContainer *_devMgr;
249 redhawk::DomainManagerContainer *_domMgr;
redhawk::DomainManagerContainer * getDomainManager()
Definition: Service_impl.h:237
bool initialConfiguration
Definition: Service_impl.h:210
Service_impl::AnyComparisonType compareAnyToZero(CORBA::Any &first)
virtual void resolveDeviceManager()
AnyComparisonType
Definition: Service_impl.h:200
Service_impl::AnyComparisonType compareAnys(CORBA::Any &first, CORBA::Any &second)
omni_mutex component_running_mutex
Definition: Service_impl.h:243
CF::Properties originalCap
Definition: Service_impl.h:211
omni_condition component_running
Definition: Service_impl.h:244
CF::DeviceManager_ptr _deviceManager
Definition: Service_impl.h:209
Definition: Service_impl.h:204
virtual void registerServiceWithDevMgr()
Definition: Service_impl.h:40
Definition: Service_impl.h:201
redhawk::DeviceManagerContainer * getDeviceManager()
Definition: Service_impl.h:233
std::string _name
Definition: Service_impl.h:213
static void start_service(T **servPtr, struct sigaction sa, int argc, char *argv[])
Definition: Service_impl.h:46
Definition: Service_impl.h:206
Definition: Service_impl.h:202
Definition: Service_impl.h:205
static std::string getLogConfig(const char *devmgr_ior, const char *log_config, std::string &devmgr_label)
Definition: Service_impl.h:132
std::string _devMgr_ior
Definition: Service_impl.h:242
Definition: Service_impl.h:207
Definition: Service_impl.h:203
virtual void terminateService()