Skip to content

Commit

Permalink
rename exposed functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KnicKnic committed Aug 18, 2019
1 parent 2a36acf commit 378fc27
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion native-powershell
4 changes: 2 additions & 2 deletions pkg/powershell/powershell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void FreeWrapper(void *ptr)
}

void InitLibraryHelper(){
InitLibrary(MallocWrapper, free);
NativePowerShell_InitLibrary(MallocWrapper, free);
}

void * MallocCopyGeneric(const void * input, unsigned long long byteCount ){
Expand Down Expand Up @@ -69,7 +69,7 @@ NativePowerShell_RunspaceHandle CreateRunspaceHelper(unsigned long long context,
if(useCommand == 0){
commandPtr = nullptr;
}
return CreateRunspace((void*)context, commandPtr, loggerPtr);
return NativePowerShell_CreateRunspace((void*)context, commandPtr, loggerPtr);
// return CreateRunspace(nullptr, Command, Logger);
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/powershell/powershell.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ func (runspace Runspace) createCommand() psCommand {
currentCommand := currentlyInvoking[len(currentlyInvoking)-1]
return currentCommand.createNested()
}
return psCommand{C.CreatePowershell(runspace.handle), runspace.runspaceContext}
return psCommand{C.NativePowerShell_CreatePowerShell(runspace.handle), runspace.runspaceContext}
}

// createNested a nested powershell command
func (command psCommand) createNested() psCommand {
return psCommand{C.CreatePowershellNested(command.handle), command.context}
return psCommand{C.NativePowerShell_CreatePowerShellNested(command.handle), command.context}
}

// Close and free a psCommand
// , call on all objects even those that are Invoked
func (command psCommand) Close() {
C.DeletePowershell(command.handle)
C.NativePowerShell_DeletePowershell(command.handle)
}

func boolToCChar(b bool) C.char {
Expand All @@ -66,7 +66,7 @@ func (command psCommand) AddCommand(commandlet string, useLocalScope bool) {
ptrwchar := unsafe.Pointer(cs)
localScope := boolToCChar(useLocalScope)

_ = C.AddCommandSpecifyScope(command.handle, (*C.wchar_t)(ptrwchar), localScope)
_ = C.NativePowerShell_AddCommandSpecifyScope(command.handle, (*C.wchar_t)(ptrwchar), localScope)
}

// AddScript to an existing powershell command
Expand All @@ -76,7 +76,7 @@ func (command psCommand) AddScript(script string, useLocalScope bool) {
ptrwchar := unsafe.Pointer(cs)
localScope := boolToCChar(useLocalScope)

_ = C.AddScriptSpecifyScope(command.handle, (*C.wchar_t)(ptrwchar), localScope)
_ = C.NativePowerShell_AddScriptSpecifyScope(command.handle, (*C.wchar_t)(ptrwchar), localScope)
}

// AddArgumentString add a string argument to an existing powershell command
Expand All @@ -85,12 +85,12 @@ func (command psCommand) AddArgumentString(argument string) {

ptrwchar := unsafe.Pointer(cs)

_ = C.AddArgument(command.handle, (*C.wchar_t)(ptrwchar))
_ = C.NativePowerShell_AddArgument(command.handle, (*C.wchar_t)(ptrwchar))
}

// AddArgument add a Object argument to an existing powershell command
func (command psCommand) AddArgument(object Object) {
_ = C.AddPSObjectArgument(command.handle, object.handle)
_ = C.NativePowerShell_AddPSObjectArgument(command.handle, object.handle)
}

// AddParameterString add a string with a parameter name to an existing powershell command
Expand All @@ -100,7 +100,7 @@ func (command psCommand) AddParameterString(paramName string, paramValue string)

cValue, _ := windows.UTF16PtrFromString(paramValue)
ptrValue := unsafe.Pointer(cValue)
_ = C.AddParameterString(command.handle, (*C.wchar_t)(ptrName), (*C.wchar_t)(ptrValue))
_ = C.NativePowerShell_AddParameterString(command.handle, (*C.wchar_t)(ptrName), (*C.wchar_t)(ptrValue))
}

// AddParameter add a Object with a parameter name to an existing powershell command
Expand All @@ -109,7 +109,7 @@ func (command psCommand) AddParameter(paramName string, object Object) {
cName, _ := windows.UTF16PtrFromString(paramName)
ptrName := unsafe.Pointer(cName)

_ = C.AddParameterObject(command.handle, (*C.wchar_t)(ptrName), object.handle)
_ = C.NativePowerShell_AddParameterObject(command.handle, (*C.wchar_t)(ptrName), object.handle)
}

func (command psCommand) completeInvoke() {
Expand All @@ -127,7 +127,7 @@ func (command psCommand) Invoke() *InvokeResults {
var count C.uint
command.context.invoking = append(command.context.invoking, command)
defer command.completeInvoke()
exception := C.InvokeCommand(command.handle, &objects, &count)
exception := C.NativePowerShell_InvokeCommand(command.handle, &objects, &count)
return makeInvokeResults(objects, count, exception)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/powershell/powershellobjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ func (obj Object) toCHandle() C.NativePowerShell_PowerShellObject {
//
// Needs to be called for every object returned from AddRef
func (obj Object) Close() {
C.ClosePowerShellObject(obj.toCHandle())
C.NativePowerShell_ClosePowerShellObject(obj.toCHandle())
}

// AddRef returns a new Object that has to also be called Close on
//
// This is useful in Callback processing, as those NativePowerShell_PowerShellObjects are auto closed, and to keep
// a reference after the function returns use AddRef
func (obj Object) AddRef() Object {
handle := C.AddPSObjectHandle(obj.toCHandle())
handle := C.NativePowerShell_AddPSObjectHandle(obj.toCHandle())
return makePowerShellObject(handle)
}

// IsNull returns true if the backing powershell object is null
func (obj Object) IsNull() bool {
return C.IsPSObjectNullptr(obj.toCHandle()) == 1
return C.NativePowerShell_IsPSObjectNullptr(obj.toCHandle()) == 1
}

// Type returns the (System.Object).GetType().ToString() function
Expand All @@ -71,7 +71,7 @@ func (obj Object) Type() string {
return "nullptr"
}

var str *C.wchar_t = C.GetPSObjectType(obj.toCHandle())
var str *C.wchar_t = C.NativePowerShell_GetPSObjectType(obj.toCHandle())
defer C.FreeWrapper(unsafe.Pointer(str))
return makeString(str)
}
Expand All @@ -84,7 +84,7 @@ func (obj Object) ToString() string {
return "nullptr"
}

var str *C.wchar_t = C.GetPSObjectToString(obj.toCHandle())
var str *C.wchar_t = C.NativePowerShell_GetPSObjectToString(obj.toCHandle())
defer C.FreeWrapper(unsafe.Pointer(str))
return makeString(str)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/powershell/runspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ func CreateRunspace(loggerCallback logger.Simple, callback CallbackHolder) Runsp
// Close and free a Runspace
func (runspace Runspace) Close() {
deleteRunspaceContextLookup(runspace.contextLookup)
C.DeleteRunspace(runspace.handle)
C.NativePowerShell_DeleteRunspace(runspace.handle)
}

0 comments on commit 378fc27

Please sign in to comment.