ref: refs/heads/master
commit cdaf897a6b03d07f03dd3fbd6f2f22e7c991ecfd
Author: Michael Calmer
Date: Fri Jul 24 17:50:16 2009 +0200
adapt changed comm structure
---
helper/installHelper.cc | 5 +++
helper/installHelper.h | 10 +++++-
helper/test.cc | 13 +++++++-
src/SUSE_SoftwareInstallationJobProvider.cc | 8 ++++-
src/SUSE_SoftwareInstallationServiceProvider.cc | 39 ++++++++++++----------
5 files changed, 54 insertions(+), 21 deletions(-)
diff --git a/helper/installHelper.cc b/helper/installHelper.cc
index b53fece..0617bce 100644
--- a/helper/installHelper.cc
+++ b/helper/installHelper.cc
@@ -53,6 +53,11 @@ try {
} while( ! rec.empty() );
MIL << "Received." << endl;
+ do {
+ rec = textExch->get();
+ USR << zypp::str::strtonum(rec) << endl;
+ } while( ! rec.empty() );
+ MIL << "Received." << endl;
for(int i = 0; i < 10; ++i)
{
diff --git a/helper/installHelper.h b/helper/installHelper.h
index 0aad237..4ddd30a 100644
--- a/helper/installHelper.h
+++ b/helper/installHelper.h
@@ -1,6 +1,8 @@
#ifndef INSTALLHELPER_H
#define INSTALLHELPER_H
+#include
+
#include
#include
#include
@@ -120,15 +122,21 @@ namespace cmpizypp
struct TextExch : public ShmData
{
- enum { buffsize = 1 };
+ enum { buffsize = 1024 };
TextExch()
: _filled( false )
{}
+ void sendEOD()
+ { send(""); }
+
void send( const char * text_r )
{ send( std::string( text_r ? text_r : "" ) ); }
+ void send( uint16_t int_r )
+ { send( zypp::str::numstring( int_r ) ); }
+
void send( const std::string & text_r )
{
bool noEOD = true;
diff --git a/helper/test.cc b/helper/test.cc
index b52da6a..80d2e72 100644
--- a/helper/test.cc
+++ b/helper/test.cc
@@ -50,15 +50,18 @@ try {
shm_remove() { shared_memory_object::remove(SHM_NAME); }
~shm_remove() { shared_memory_object::remove(SHM_NAME); }
} remover;
+ INT << "=1" << endl;
if ( ! shm().construct<Comm>("Comm")() )
{
throw std::string( "Out of shmem constructing Comm" );
}
+ INT << "=2" << endl;
if ( ! shm().find_or_construct<TextExch>("TextExch")() )
{
throw std::string( "Out of shmem constructing TextExch" );
}
+ INT << "=3" << endl;
ShmAccess<Comm> comm( shm(), "Comm" ); // blocks the helper
USR << "STATUS: " << comm << endl;
@@ -75,13 +78,21 @@ try {
"Warum auch nicht",
"Es hat ja Zeit",
};
+ uint16_t iargs[] = { 4,5,10,32876 };
+
ShmAccessUnlocked<TextExch> textExch( shm(), "TextExch" );
MIL << "Send data..." << endl;
for_( it, arrayBegin( args ), arrayEnd( args ) )
{
textExch->send( *it );
}
- textExch->send( 0 );
+ textExch->sendEOD();
+ MIL << "Send data..." << endl;
+ for_( it, arrayBegin( iargs ), arrayEnd( iargs ) )
+ {
+ textExch->send( *it );
+ }
+ textExch->sendEOD();
MIL << "Sent." << endl;
diff --git a/src/SUSE_SoftwareInstallationJobProvider.cc b/src/SUSE_SoftwareInstallationJobProvider.cc
index 9845ac7..882cad5 100644
--- a/src/SUSE_SoftwareInstallationJobProvider.cc
+++ b/src/SUSE_SoftwareInstallationJobProvider.cc
@@ -103,6 +103,7 @@ CmpiStatus SUSE_SoftwareInstallationJobProviderClass::getInstance( const CmpiCon
uint16_t percent = 0;
uint16_t error = 0;
+ try
{
managed_shared_memory managed_shm( open_only, SHM_NAME );
ShmAccess<Comm> comm( managed_shm, "Comm" );
@@ -112,10 +113,15 @@ CmpiStatus SUSE_SoftwareInstallationJobProviderClass::getInstance( const CmpiCon
return CmpiStatus(CMPI_RC_ERR_FAILED, "Invalid InstanceID. No such process.");
}
- status = comm->status;
+ status = comm->_status;
percent = comm->percent;
error = comm->error;
}
+ catch(std::string & err)
+ {
+ _CMPIZYPP_TRACE(1,("Exception: %s", err.c_str()));
+ throw err;
+ }
const char * keys[] = { "InstanceID" };
ci.setPropertyFilter( properties, keys );
diff --git a/src/SUSE_SoftwareInstallationServiceProvider.cc b/src/SUSE_SoftwareInstallationServiceProvider.cc
index 9b476a2..b0fd5c6 100644
--- a/src/SUSE_SoftwareInstallationServiceProvider.cc
+++ b/src/SUSE_SoftwareInstallationServiceProvider.cc
@@ -477,22 +477,6 @@ CmpiStatus SUSE_SoftwareInstallationServiceProviderClass::refreshAllRepositories
int SUSE_SoftwareInstallationServiceProviderClass::createJob(const CmpiContext &ctx, const CmpiArray &swIdentities,
const CmpiArray &installOptions, CmpiInstance &job)
{
- // write task list
- std::string path( zypp::filesystem::TmpFile().path().asString() );
- std::ofstream o( path.c_str() );
- for(uint i = 0; i < swIdentities.size(); ++i)
- {
- CmpiString s = swIdentities[i];
- o << s.charPtr() << endl;
- }
- o << "InstallOptions:" << endl;
- for(uint i = 0; i < installOptions.size(); ++i)
- {
- uint16_t opt = installOptions[i];
- o << opt << endl;
- }
- o.close();
-
shared_memory_object::remove(SHM_NAME);
_CMPIZYPP_TRACE(1,("Creating shared memory"));
@@ -505,11 +489,14 @@ int SUSE_SoftwareInstallationServiceProviderClass::createJob(const CmpiContext &
_CMPIZYPP_TRACE(1,("Out of shmem constructing Comm"));
throw std::string( "Out of shmem constructing Comm" );
}
+ if ( ! managed_shm.find_or_construct<TextExch>("TextExch")() )
+ {
+ _CMPIZYPP_TRACE(1,("Out of shmem constructing TextExch"));
+ throw std::string( "Out of shmem constructing TextExch" );
+ }
ShmAccess<Comm> comm( managed_shm, "Comm" ); // blocks the helper
- strncpy( comm->dataStr, path.c_str(), STR_SIZE );
-
_CMPIZYPP_TRACE(1,("fork and execute installHelper"));
ExternalProgram helper( "/usr/lib/cmpi-zypp/installHelper" );
@@ -518,6 +505,22 @@ int SUSE_SoftwareInstallationServiceProviderClass::createJob(const CmpiContext &
comm->pid = helper.getpid();
comm.release(); // go...
+ ShmAccessUnlocked<TextExch> textExch( managed_shm, "TextExch" );
+ // write task list
+ for(uint i = 0; i < swIdentities.size(); ++i)
+ {
+ CmpiString s = swIdentities[i];
+ textExch->send( s.charPtr() );
+ }
+ textExch->sendEOD();
+
+ for(uint i = 0; i < installOptions.size(); ++i)
+ {
+ uint16_t opt = installOptions[i];
+ textExch->send( opt );
+ }
+ textExch->sendEOD();
+
CmpiObjectPath jobOP(job.getObjectPath().getNameSpace(), "SUSE_SoftwareInstallationJob");
jobOP.setKey("InstanceID", str::form("SUSE:%d", helper.getpid()).c_str());
job = broker->getInstance( ctx, jobOP, NULL ); // source instance
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org