2014-10-16 1 views
0

선택적 오류 매개 변수가 포함 된 SOAP 응답 구조가 있습니다. 구문 오류를 생성하지 않았기 때문에이 매개 변수를 축약했습니다. 두 클래스 모두 gsoap에 의해 생성됩니다.Gsoap에서 C++ 객체를 할당하는 방법

응답 개체

class SOAP_CMAC ns1__LoginResponse : public ns1__Response 
{ 
public: 
    class ns1__Error *Error; /* optional element of type ns1:Error */ 
    int *SessionID; /* SOAP 1.2 RPC return element (when namespace qualified) */ /* optional element of type xsd:int */ 
public: 
    virtual int soap_type() const { return 127; } /* = unique type id SOAP_TYPE_ns1__LoginResponse */ 
    virtual void soap_default(struct soap*); 
    virtual void soap_serialize(struct soap*) const; 
    virtual int soap_put(struct soap*, const char*, const char*) const; 
    virtual int soap_out(struct soap*, const char*, int, const char*) const; 
    virtual void *soap_get(struct soap*, const char*, const char*); 
    virtual void *soap_in(struct soap*, const char*, const char*); 
      ns1__LoginResponse() { ns1__LoginResponse::soap_default(NULL); } 
    virtual ~ns1__LoginResponse() { } 
}; 

오류 개체

class SOAP_CMAC ns1__Error : public xsd__anyType 
{ 
public: 
    std::string *Code; /* optional element of type xsd:string */ 
    std::string *Description; /* optional element of type xsd:string */ 
public: 
    virtual int soap_type() const { return 100; } /* = unique type id SOAP_TYPE_ns1__Error */ 
    virtual void soap_default(struct soap*); 
    virtual void soap_serialize(struct soap*) const; 
    virtual int soap_put(struct soap*, const char*, const char*) const; 
    virtual int soap_out(struct soap*, const char*, int, const char*) const; 
    virtual void *soap_get(struct soap*, const char*, const char*); 
    virtual void *soap_in(struct soap*, const char*, const char*); 
      ns1__Error() { ns1__Error::soap_default(NULL); } 
    virtual ~ns1__Error() { } 
}; 

내 서비스에서 오류를 감지 할 때 나는이 ns1__Error 객체를 할당해야합니다.

나는 soap_malloc

ns1__Error* err = (ns1__Error*)soap_malloc(soap_context, sizeof(ns1__Error)); 

를 사용하여 시도했지만 나는 이것이 치명적 결함이 실현. gsoap이 나중에 객체 메소드 중 하나를 호출하면 충돌이 발생합니다. 개체 생성자가 호출되지 않았습니다.

soap_malloc을 호출하면 new를 사용하여 생성자를 호출 한 다음 작동하지만 소멸자를 호출 할 곳이 없습니다.

void* errmem = soap_malloc(soap_context, sizeof(ns1__Error)); 
ns1__Error err= new (errmem) ns1__Error(); 

이 충돌하지만 gsoap 아직 나에게 그냥 할 수있는 메커니즘을 제공하지 않는 것, 나에게 클래스를 만들어 그렇게 내가 나 자신을 할당 할 필요가 만든 특히, 잘못된 느낌하지 않습니다. 또한 소멸자가 호출되지 않았기 때문에 할당 해제 시간에 내 객체를 잠재적으로 잘못된 상태로 유지합니다.

soap_new_Class 기능에 대한 이야기가 있습니다. 그러나 버전 2.8.18에서는이 기능을 볼 수 없습니다.

개체를 올바르게 할당하고 구성하고 소멸 시키도록 GPO를 어떻게 만들 수 있습니까? gsoap은 개체가 완료되면 정리할 수 있습니까?

답변

0

Gsoap은 wsdl 또는 헤더 파일에서 생성하는 모든 유형에 대한 할당 함수를 정의합니다. 그것은 내가 문자 그대로의 함수 이름을 의미하는 것으로 soap_new_Class을 오해 질문에 보일 것입니다 : 그것은

X* soap_new_X(struct soap* s, int num = -1); 

편집 유사한 함수를 정의하는 타입 X의

.

num 유형 X의 할당 된 객체 배열을 반환합니다 (-1은 단일 객체를 할당하는 특별한 경우 임). 요청이 처리 된 후 soap_destroy으로 전화를 걸면 할당 취소 될 개체의 gsoaps 내부 레지스트리에 포함됩니다.

내 오류 개체는 다음과 같습니다.

inline ns1__Error * soap_new_ns1__Error(struct soap *soap, int n = -1); 

ns1__Error * soap_new_req_ns1__Error(struct soap *soap, int mandatory_param); 

이것은 객체를 할당한다 작성된 제 기능이 아니라 모든 필수 파라미터의 설정을 허용한다.

이 함수 프로토 타입은 SoapH.h에 정의되어 있습니다. 파일 이름은 코드를 생성 할 때 전달하는 매개 변수에 따라 변경 될 것입니다.

gsoap (또는 적어도 내 용도로)에 일반적인 std :: string을 할당하려면 함수가 있어야합니다.

+0

NON 필수 ** bool ** 필드가 포함 된 wsdl 개체가 있습니다. gsoap은이 필드에 ** bool 포인터 **가있는 C++ 구조를 생성합니다. 그러나 나는'soap_new_std__bool' 메쏘드를 찾을 수 없습니다 : 그것은'new bool'을 사용할 것으로 기대합니까? –

+0

@MarcoStramezzi 나는 내 자신의 질문에 대답 한 지 오래되었습니다. 당신은 확실히 원시 새로운'bool'을 사용해서는 안됩니다. 나는 무엇을해야할지 모르겠다. 아마도 생성 된 코드를 열고 법안에 맞는 함수를 찾아보십시오. 그렇지 않으면 c에서 malloc처럼 사용할 수있는 일반 할당 함수가있을 수 있으며 단지 크기를 제공합니다. –

관련 문제